'How to unmerge a Git merge?
I accidentally did a git pull origin master from dev, and master got merged into dev.
Is it possible to unmerge?
I've already seen different solutions, i tried this one from both dev and master :
git revert -m 1 <commit> (once each)
But i got : Everything is up-to-date, each time
Solution 1:[1]
If you haven't committed the merge, then use:
git merge --abort
Solution 2:[2]
If the merge has been accepted accidentally by git merge --continue or if the changes are auto committed when git pull <branch>, then we can revert or undo the very recent merge by executing
git reset --merge HEAD~1
This command reverts our repository to the last commit. HEAD refers to the current state of your repository; HEAD~1 is the last commit in your repository.
Solution 3:[3]
git revert -m allows to un-merge still keeping the history of both merge and un-do operation. Might be good for documenting probably.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Prasanth Rajendran |
| Solution 3 | poige |
