{"thread":{"id":"14410","subject":"how to undo a git merge?","startedAt":"2008-07-11T16:16:15Z","lastAt":"2008-07-11T18:55:43Z","messageCount":8,"participants":["ff","Miklos Vajna","Jakub Narebski","Sverre Rabbelier"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"82976","messageId":"fa7d16350807110916x689e316fr6bae01f28e2e1acb@mail.gmail.com","threadId":"14410","inReplyTo":null,"subject":"how to undo a git merge?","fromName":"ff","fromEmail":"ff@member.org","sentAt":"2008-07-11T16:16:15Z","receivedAt":"2008-07-11T16:16:15Z","isPatch":false,"sender":{"key":"ff@member.org","avatar":null},"body":"Hello,\n\nI'm a git lover with a question.\n\nI have two git branches that stem from the same exact master branch.\nMany commits happened independently on these two branches overtime.\nThen, I inadvertently did a merge from one branch into another. The branch\nwhere I merged into now has mixed commits, and also a commit for the merge\nitself. I then had more commits added to the branch that I merged into.\n\nNow I would like to revert the merge... what is the best way of doing that?\nI would like very much to use something like git-revert <merge_commit_id>\nBut that does not seem to work.\n\nAny help/pointers of an example illustrating solution to this case\nwould be greatly\nappreciated!\n\nRegards,\n\n-- ff@member.org\n"},{"id":"82978","messageId":"20080711161923.GE10347@genesis.frugalware.org","threadId":"14410","inReplyTo":"fa7d16350807110916x689e316fr6bae01f28e2e1acb@mail.gmail.com","subject":"Re: how to undo a git merge?","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-07-11T16:19:23Z","receivedAt":"2008-07-11T16:19:23Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Fri, Jul 11, 2008 at 12:16:15PM -0400, ff <ff@member.org> wrote:\n> Now I would like to revert the merge... what is the best way of doing that?\n> I would like very much to use something like git-revert <merge_commit_id>\n> But that does not seem to work.\n\ngit revert has a '-m' option to revert merges. See the manpage.\n\n> Any help/pointers of an example illustrating solution to this case\n> would be greatly\n> appreciated!\n\nActually if you just did that merge by accident, then probably you want\n'git reset --hard HEAD^', not git revert, I think.\n"},{"id":"82985","messageId":"m34p6we43y.fsf@localhost.localdomain","threadId":"14410","inReplyTo":"fa7d16350807110916x689e316fr6bae01f28e2e1acb@mail.gmail.com","subject":"Re: how to undo a git merge?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-07-11T17:13:35Z","receivedAt":"2008-07-11T17:13:35Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"ff <ff@member.org> writes:\n\n> I have two git branches that stem from the same exact master branch.\n> Many commits happened independently on these two branches overtime.\n> Then, I inadvertently did a merge from one branch into another. The branch\n> where I merged into now has mixed commits, and also a commit for the merge\n> itself. I then had more commits added to the branch that I merged into.\n> \n> Now I would like to revert the merge... what is the best way of doing that?\n> I would like very much to use something like git-revert <merge_commit_id>\n> But that does not seem to work.\n\nIf you have published history, then the only sane option is\n\"git revert -m\".  If you haven't published history, you can\ntry \"git rebase --interactive\".\n\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"82986","messageId":"20080711181413.GI10347@genesis.frugalware.org","threadId":"14410","inReplyTo":"fa7d16350807111107o40c5cbb5xc06c3c56b16b7499@mail.gmail.com","subject":"Re: how to undo a git merge?","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-07-11T18:14:13Z","receivedAt":"2008-07-11T18:14:13Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"[ Did you reply off-list intentionally? ]\n\nOn Fri, Jul 11, 2008 at 02:07:44PM -0400, ff <ff@member.org> wrote:\n> thank you.\n> \n> I did see the -m option in the revert man page. It talks about\n> \"parent\" and I did\n> not understand what that is. Is parent the commit id of the merge commit?\n> \n> Thanks again!\n\nhttp://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_parent\n\nA merge commit has two parents, but obviously only one of the was the\nHEAD commit before the merge. So when you revert a merge, you need to\nspecify which which parent's tree should be the tree of the new HEAD.\n\nFor example, if you were on branch 'master' and you merged 'foo' to\nmaster using 'git merge foo', and you want to revert that merge then you\nneed '-m 1'.\n"},{"id":"82990","messageId":"200807112036.13745.jnareb@gmail.com","threadId":"14410","inReplyTo":"fa7d16350807111108y3a8a7c3di19598a56dbbcdc15@mail.gmail.com","subject":"Re: how to undo a git merge?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-07-11T18:36:12Z","receivedAt":"2008-07-11T18:36:12Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"ff (?) wrote:\n> \n> I did see the -m option in the revert man page. It talks about\n> \"parent\" and I did not understand what that is. Is parent the commit\n> id of the merge commit? \n\nIt is _number_ of parent.\n\n\n   -m parent-number, --mainline parent-number\n          Usually you cannot revert a merge because you do not know which side\n          of  the  merge should be considered the mainline. This option speci-\n          fies the parent number (starting from 1) of the mainline and  allows\n          revert to reverse the change relative to the specified parent.\n\n\nMerge commit has more than one parent.  What git-revert does, it\ncreates commit which reverts the changes, as if applying \"reversal\"\ndiff, \"git diff -R <revision>^<parent-number> <revision>\".\n\n-- \nJakub Narebski\nPoland\n"},{"id":"82992","messageId":"fa7d16350807111146m18b0ca9q6902c2167bfd3512@mail.gmail.com","threadId":"14410","inReplyTo":"20080711181413.GI10347@genesis.frugalware.org","subject":"Re: how to undo a git merge?","fromName":"ff","fromEmail":"ff@member.org","sentAt":"2008-07-11T18:46:15Z","receivedAt":"2008-07-11T18:46:15Z","isPatch":false,"sender":{"key":"ff@member.org","avatar":null},"body":"> [ Did you reply off-list intentionally? ]\n\nooops... yes... I'm scared of the reply-all button. :)\n\n> For example, if you were on branch 'master' and you merged 'foo' to\n> master using 'git merge foo', and you want to revert that merge then you\n> need '-m 1'.\n\nOk, so... sorry for not getting it completely, even after reading the info.\n\nIn your example, how and why you can determine that the number 1\nrepresents the \"foo\" branch? Would \"-m 2\" represent the master branch?\nIn your example is there any other choice for the \"-m\" number to use?\n\n-- ff\n\n\n\nOn Fri, Jul 11, 2008 at 2:14 PM, Miklos Vajna <vmiklos@frugalware.org> wrote:\n> [ Did you reply off-list intentionally? ]\n>\n> On Fri, Jul 11, 2008 at 02:07:44PM -0400, ff <ff@member.org> wrote:\n>> thank you.\n>>\n>> I did see the -m option in the revert man page. It talks about\n>> \"parent\" and I did\n>> not understand what that is. Is parent the commit id of the merge commit?\n>>\n>> Thanks again!\n>\n> http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_parent\n>\n> A merge commit has two parents, but obviously only one of the was the\n> HEAD commit before the merge. So when you revert a merge, you need to\n> specify which which parent's tree should be the tree of the new HEAD.\n>\n> For example, if you were on branch 'master' and you merged 'foo' to\n> master using 'git merge foo', and you want to revert that merge then you\n> need '-m 1'.\n>\n"},{"id":"82996","messageId":"20080711185332.GJ10347@genesis.frugalware.org","threadId":"14410","inReplyTo":"fa7d16350807111146m18b0ca9q6902c2167bfd3512@mail.gmail.com","subject":"Re: how to undo a git merge?","fromName":"Miklos Vajna","fromEmail":"vmiklos@frugalware.org","sentAt":"2008-07-11T18:53:32Z","receivedAt":"2008-07-11T18:53:32Z","isPatch":false,"sender":{"key":"vmiklos@frugalware.org","avatar":"https://gravatar.com/avatar/401c1cbbb3a5d13e650c691a2c71d6fd0b80df1a01bc74d9f1972675dd58f2bd?d=mp&s=160"},"body":"On Fri, Jul 11, 2008 at 02:46:15PM -0400, ff <ff@member.org> wrote:\n> ooops... yes... I'm scared of the reply-all button. :)\n\nAlso please don't top-post, thanks. ;-)\n\n> In your example, how and why you can determine that the number 1\n> represents the \"foo\" branch? Would \"-m 2\" represent the master branch?\n> In your example is there any other choice for the \"-m\" number to use?\n\nIf the merge has two parents, then the first one is the actual branch\nand the second is the 'other' branch.\n\nSo if 'master' is checked out, you did a 'git merge foo', and you want\nto do a revert, '1' stands for 'master' and '2' for 'foo'.\n"},{"id":"82997","messageId":"bd6139dc0807111155x46a9f6acnf2d585f62342f4a6@mail.gmail.com","threadId":"14410","inReplyTo":"fa7d16350807111146m18b0ca9q6902c2167bfd3512@mail.gmail.com","subject":"Re: how to undo a git merge?","fromName":"Sverre Rabbelier","fromEmail":"alturin@gmail.com","sentAt":"2008-07-11T18:55:43Z","receivedAt":"2008-07-11T18:55:43Z","isPatch":false,"sender":{"key":"alturin@gmail.com","avatar":null},"body":"On Fri, Jul 11, 2008 at 8:46 PM, ff <ff@member.org> wrote:\n>> For example, if you were on branch 'master' and you merged 'foo' to\n>> master using 'git merge foo', and you want to revert that merge then you\n>> need '-m 1'.\n>\n> In your example, how and why you can determine that the number 1\n> represents the \"foo\" branch? Would \"-m 2\" represent the master branch?\n> In your example is there any other choice for the \"-m\" number to use?\n\nWhen you perform a merge on branch A, like so:\ngit checkout A  # first switch to the branch you want the merge to be on\ngit merge B  # now do the actual merge with the branch you want to merge with\n\nThe resulting merge commit will have the head of A as it's first\nparent, and the head of B as it's second parent. With the -m switch\nyou can specify which parent you want to follow. If for example, you\nhave a three-way merge, like so ..:\ngit checkout A\ngit merge B C\n.. the resulting merge commit would have A as it's first, B as it's\nsecond and C as it's third parent. If you want to revert to the state\nof C then you specify -m 3, so that the third parent is chosen. If you\nperformed the merge on the branch that you want to revert to, you\nalways specify -m 1. If you did this ..:\ngit checkout B\ngit merge A\n.. and then you want to restore the state of branch A, you use '-m 2'.\n\n-- \nCheers,\n\nSverre Rabbelier\n"}]}