From: Sverre Rabbelier Date: Fri, 11 Jul 2008 18:55:43 GMT Subject: Re: how to undo a git merge? Message-ID: In-Reply-To: On Fri, Jul 11, 2008 at 8:46 PM, ff wrote: >> For example, if you were on branch 'master' and you merged 'foo' to >> master using 'git merge foo', and you want to revert that merge then you >> need '-m 1'. > > In your example, how and why you can determine that the number 1 > represents the "foo" branch? Would "-m 2" represent the master branch? > In your example is there any other choice for the "-m" number to use? When you perform a merge on branch A, like so: git checkout A # first switch to the branch you want the merge to be on git merge B # now do the actual merge with the branch you want to merge with The resulting merge commit will have the head of A as it's first parent, and the head of B as it's second parent. With the -m switch you can specify which parent you want to follow. If for example, you have a three-way merge, like so ..: git checkout A git merge B C .. the resulting merge commit would have A as it's first, B as it's second and C as it's third parent. If you want to revert to the state of C then you specify -m 3, so that the third parent is chosen. If you performed the merge on the branch that you want to revert to, you always specify -m 1. If you did this ..: git checkout B git merge A .. and then you want to restore the state of branch A, you use '-m 2'. -- Cheers, Sverre Rabbelier