feat(git): GitWorkingCopy.discard() to drop local work and come back to the remote state #71

Closed
opened 2026-11-19 07:43:53 +00:00 by crapougnax · 0 comments
Owner

Need

An application that commits and pushes one change at a time (for instance one commit per save, signed by the person who saved) needs a way out when the remote refuses the push because someone else pushed first: drop the local commit, come back to the remote state, and try again from there. GitWorkingCopy has refresh() (fast-forward only) but no way to drop local work, so the working copy stays diverged and every later refresh() fails.

Proposal

GitWorkingCopy.discard():

  • with a remote: fetches the branch, then resets the working copy to it — local commits, staged and unstaged changes and untracked files are dropped (ignored files are kept);
  • against an empty remote (no branch yet): comes back to an empty branch;
  • without a remote: drops uncommitted changes only, back to the last commit;
  • runs in the same queue as the other operations; never touches the remote.

Documented in the package README (EN, FR) with the commit / push / discard / retry pattern.

## Need An application that commits and pushes one change at a time (for instance one commit per save, signed by the person who saved) needs a way out when the remote refuses the push because someone else pushed first: drop the local commit, come back to the remote state, and try again from there. `GitWorkingCopy` has `refresh()` (fast-forward only) but no way to drop local work, so the working copy stays diverged and every later `refresh()` fails. ## Proposal `GitWorkingCopy.discard()`: - with a remote: fetches the branch, then resets the working copy to it — local commits, staged and unstaged changes and untracked files are dropped (ignored files are kept); - against an empty remote (no branch yet): comes back to an empty branch; - without a remote: drops uncommitted changes only, back to the last commit; - runs in the same queue as the other operations; never touches the remote. Documented in the package README (EN, FR) with the commit / push / discard / retry pattern.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
quatrain/core#71
No description provided.