Git: how to do a reverse merge commit?

With SVN it's easy to collapse-merge commit, but how to do it with Git?

+106
git merge
Nov 27 '09 at 15:54
source share
5 answers

To create a new commit that β€œrolls back” changes to a previous commit, use:

$ git revert <commit> 

You can also actually remove a commit from an arbitrary point in the past by rebooting and then resetting, but you really don't want to do this if you have already pushed your commits to another repository (or someone else clicked from you).

+102
Nov 27 '09 at 16:09
source share

To undo a merge commit, you need to use: git revert -m <parent number> . So, for example, to undo the most recent merge commit using parent number 1, you would use:

 git revert -m 1 HEAD 

To undo a merge commit before the last commit, you must do:

 git revert -m 1 HEAD^ 

Use git show <merge commit SHA1> to see parents, numbering is the order in which they appear, for example, Merge: e4c54b3 4725ad2

git merge documentation: http://schacon.github.com/git/git-merge.html

git merge discussion (confusing but very detailed): http://schacon.github.com/git/howto/revert-a-faulty-merge.txt

+105
Dec 29 '09 at 6:57
source share

If you understand correctly, you are talking about how to make

 svn merge -rn:n-1 

to return from an earlier commit, in which case you're probably looking

 git revert 
+4
Nov 27 '09 at 16:09
source share
 git reset --hard HEAD^ 

Use the above command to revert merge changes.

-one
Jul 16 '14 at 21:34
source share

If you do not want to comment or want to commit later (a commit message will still be prepared for you, which you can also edit):

 git revert -n <commit> 
-one
Jan 29 '17 at 10:54 on
source share



All Articles