git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* how to undo a git merge?
@ 2008-07-11 16:16 ff
  2008-07-11 16:19 ` Miklos Vajna
  2008-07-11 17:13 ` Jakub Narebski
  0 siblings, 2 replies; 8+ messages in thread
From: ff @ 2008-07-11 16:16 UTC (permalink / raw)
  To: git

Hello,

I'm a git lover with a question.

I have two git branches that stem from the same exact master branch.
Many commits happened independently on these two branches overtime.
Then, I inadvertently did a merge from one branch into another. The branch
where I merged into now has mixed commits, and also a commit for the merge
itself. I then had more commits added to the branch that I merged into.

Now I would like to revert the merge... what is the best way of doing that?
I would like very much to use something like git-revert <merge_commit_id>
But that does not seem to work.

Any help/pointers of an example illustrating solution to this case
would be greatly
appreciated!

Regards,

-- ff@member.org

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
  2008-07-11 16:16 how to undo a git merge? ff
@ 2008-07-11 16:19 ` Miklos Vajna
       [not found]   ` <fa7d16350807111107o40c5cbb5xc06c3c56b16b7499@mail.gmail.com>
  2008-07-11 17:13 ` Jakub Narebski
  1 sibling, 1 reply; 8+ messages in thread
From: Miklos Vajna @ 2008-07-11 16:19 UTC (permalink / raw)
  To: ff; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 549 bytes --]

On Fri, Jul 11, 2008 at 12:16:15PM -0400, ff <ff@member.org> wrote:
> Now I would like to revert the merge... what is the best way of doing that?
> I would like very much to use something like git-revert <merge_commit_id>
> But that does not seem to work.

git revert has a '-m' option to revert merges. See the manpage.

> Any help/pointers of an example illustrating solution to this case
> would be greatly
> appreciated!

Actually if you just did that merge by accident, then probably you want
'git reset --hard HEAD^', not git revert, I think.

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
  2008-07-11 16:16 how to undo a git merge? ff
  2008-07-11 16:19 ` Miklos Vajna
@ 2008-07-11 17:13 ` Jakub Narebski
       [not found]   ` <fa7d16350807111108y3a8a7c3di19598a56dbbcdc15@mail.gmail.com>
  1 sibling, 1 reply; 8+ messages in thread
From: Jakub Narebski @ 2008-07-11 17:13 UTC (permalink / raw)
  To: ff; +Cc: git

ff <ff@member.org> writes:

> I have two git branches that stem from the same exact master branch.
> Many commits happened independently on these two branches overtime.
> Then, I inadvertently did a merge from one branch into another. The branch
> where I merged into now has mixed commits, and also a commit for the merge
> itself. I then had more commits added to the branch that I merged into.
> 
> Now I would like to revert the merge... what is the best way of doing that?
> I would like very much to use something like git-revert <merge_commit_id>
> But that does not seem to work.

If you have published history, then the only sane option is
"git revert -m".  If you haven't published history, you can
try "git rebase --interactive".

-- 
Jakub Narebski
Poland
ShadeHawk on #git

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
       [not found]   ` <fa7d16350807111107o40c5cbb5xc06c3c56b16b7499@mail.gmail.com>
@ 2008-07-11 18:14     ` Miklos Vajna
  2008-07-11 18:46       ` ff
  0 siblings, 1 reply; 8+ messages in thread
From: Miklos Vajna @ 2008-07-11 18:14 UTC (permalink / raw)
  To: ff; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 771 bytes --]

[ Did you reply off-list intentionally? ]

On Fri, Jul 11, 2008 at 02:07:44PM -0400, ff <ff@member.org> wrote:
> thank you.
> 
> I did see the -m option in the revert man page. It talks about
> "parent" and I did
> not understand what that is. Is parent the commit id of the merge commit?
> 
> Thanks again!

http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_parent

A merge commit has two parents, but obviously only one of the was the
HEAD commit before the merge. So when you revert a merge, you need to
specify which which parent's tree should be the tree of the new HEAD.

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'.

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
       [not found]   ` <fa7d16350807111108y3a8a7c3di19598a56dbbcdc15@mail.gmail.com>
@ 2008-07-11 18:36     ` Jakub Narebski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Narebski @ 2008-07-11 18:36 UTC (permalink / raw)
  To: ff; +Cc: git

ff (?) wrote:
> 
> I did see the -m option in the revert man page. It talks about
> "parent" and I did not understand what that is. Is parent the commit
> id of the merge commit? 

It is _number_ of parent.


   -m parent-number, --mainline parent-number
          Usually you cannot revert a merge because you do not know which side
          of  the  merge should be considered the mainline. This option speci-
          fies the parent number (starting from 1) of the mainline and  allows
          revert to reverse the change relative to the specified parent.


Merge commit has more than one parent.  What git-revert does, it
creates commit which reverts the changes, as if applying "reversal"
diff, "git diff -R <revision>^<parent-number> <revision>".

-- 
Jakub Narebski
Poland

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
  2008-07-11 18:14     ` Miklos Vajna
@ 2008-07-11 18:46       ` ff
  2008-07-11 18:53         ` Miklos Vajna
  2008-07-11 18:55         ` Sverre Rabbelier
  0 siblings, 2 replies; 8+ messages in thread
From: ff @ 2008-07-11 18:46 UTC (permalink / raw)
  To: Miklos Vajna; +Cc: git

> [ Did you reply off-list intentionally? ]

ooops... yes... I'm scared of the reply-all button. :)

> 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'.

Ok, so... sorry for not getting it completely, even after reading the info.

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?

-- ff



On Fri, Jul 11, 2008 at 2:14 PM, Miklos Vajna <vmiklos@frugalware.org> wrote:
> [ Did you reply off-list intentionally? ]
>
> On Fri, Jul 11, 2008 at 02:07:44PM -0400, ff <ff@member.org> wrote:
>> thank you.
>>
>> I did see the -m option in the revert man page. It talks about
>> "parent" and I did
>> not understand what that is. Is parent the commit id of the merge commit?
>>
>> Thanks again!
>
> http://www.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_parent
>
> A merge commit has two parents, but obviously only one of the was the
> HEAD commit before the merge. So when you revert a merge, you need to
> specify which which parent's tree should be the tree of the new HEAD.
>
> 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'.
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
  2008-07-11 18:46       ` ff
@ 2008-07-11 18:53         ` Miklos Vajna
  2008-07-11 18:55         ` Sverre Rabbelier
  1 sibling, 0 replies; 8+ messages in thread
From: Miklos Vajna @ 2008-07-11 18:53 UTC (permalink / raw)
  To: ff; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 619 bytes --]

On Fri, Jul 11, 2008 at 02:46:15PM -0400, ff <ff@member.org> wrote:
> ooops... yes... I'm scared of the reply-all button. :)

Also please don't top-post, thanks. ;-)

> 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?

If the merge has two parents, then the first one is the actual branch
and the second is the 'other' branch.

So if 'master' is checked out, you did a 'git merge foo', and you want
to do a revert, '1' stands for 'master' and '2' for 'foo'.

[-- Attachment #2: Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: how to undo a git merge?
  2008-07-11 18:46       ` ff
  2008-07-11 18:53         ` Miklos Vajna
@ 2008-07-11 18:55         ` Sverre Rabbelier
  1 sibling, 0 replies; 8+ messages in thread
From: Sverre Rabbelier @ 2008-07-11 18:55 UTC (permalink / raw)
  To: ff; +Cc: Miklos Vajna, git

On Fri, Jul 11, 2008 at 8:46 PM, ff <ff@member.org> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-07-11 18:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-11 16:16 how to undo a git merge? ff
2008-07-11 16:19 ` Miklos Vajna
     [not found]   ` <fa7d16350807111107o40c5cbb5xc06c3c56b16b7499@mail.gmail.com>
2008-07-11 18:14     ` Miklos Vajna
2008-07-11 18:46       ` ff
2008-07-11 18:53         ` Miklos Vajna
2008-07-11 18:55         ` Sverre Rabbelier
2008-07-11 17:13 ` Jakub Narebski
     [not found]   ` <fa7d16350807111108y3a8a7c3di19598a56dbbcdc15@mail.gmail.com>
2008-07-11 18:36     ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).