If you are in the middle of a complex merge or rebase and realize you've made a mistake, how do you return the repository to its exact state before the operation started?
Last updated
While still in progress, run
git merge --abortorgit rebase --abortto restore the pre-operation state.If already finished, run
git reset --hard ORIG_HEAD(Git's saved pre-operation position), or reset to the exact SHA found ingit reflog.--harddiscards uncommitted work, so stash or commit anything worth keeping first.
- https://git-scm.com/docs/git-merge/2.13.7
- https://git-scm.com/docs/git-rebase
- https://git-scm.com/docs/git-rebase/2.25.0
- https://git-scm.com/docs/git-rebase/2.2.3
- https://initialcommit.com/learn/git/commands/git-rebase-abort
- https://www.warp.dev/terminus/undo-a-git-rebase
- https://dev.to/yeahiasarker/undo-a-git-merge-without-breaking-your-branch-32kj
- https://www.lineserve.net/blog/mastering-git-undoing-merges-commits-guide