git reset --merge

Abort a merge and reset files to the previous HEAD while preserving unrelated local changes.

This command is useful for backing out of a problematic merge while keeping your own unrelated working-directory changes intact, effectively restoring the repository to the state before the merge began without being as destructive as a full hard reset.

This command uses reset with the --merge flag, which resets the current branch to HEAD (or to a specified commit if you add one, like git reset --merge HEAD~1) and updates the index and working tree only for files that are involved in the merge, leaving other local modifications untouched. The --merge option behaves similarly to --mixed in that it resets the index to the target commit, but it is more conservative with the working tree: for paths that were not affected by the merge, it keeps your changes; for paths that were changed by the merge, it restores them to the pre-merge state. If a merge is in progress, this command also clears the merge state (like MERGE_HEAD), effectively canceling the merge attempt.

This is particularly helpful when a merge introduced many conflicts or unwanted changes and you decide it’s easier to abandon the merge than to resolve everything; after running this, you can try the merge again, maybe with different options or after preparing your branch differently. If you want more aggressive cleanup, git reset --hard completely discards all working-directory and index changes (including unrelated ones), while git reset --mixed (or just git reset) resets the index but keeps working-directory changes so you can re-stage them selectively. For merge-specific workflows, git merge --abort is closely related and typically behaves like git reset --merge when a merge is in progress, while commands like git restore or git checkout -- <path> can be used after this command to selectively undo or keep specific file changes.

Examples:

  • git reset --merge HEAD~1
  • git reset --merge <commit-hash> (for example: git reset --merge a1b2c3d4)
Manual page
git reset
Related commands

Welcome to GitExamples!

Sign in to enable bookmarking, reminders, progress-tracking and more...