threads / discuss / 21908

Undoing merges

Subject: Undoing merges

## tl;dr

3 messages between Dec 8, 2009 and Dec 14, 2009.

replies: 2people: 2as markdown or json

Richard· Dec 8, 2009, 16:37 UTC · lore
Hi git list,

I'm trying to find out how to undo a merge. I know that my branches are independent and that I can just carry on working on them and merge again later, but I'm just trying to keep my revision graph tidier. Should I even be undoing merges?

I've searched around, but I can seem to find an answer I can follow.
Regards,
Richard
Matthieu Moy· Dec 8, 2009, 17:48 UTC · re: Richard · lore

Re: Undoing merges

"Richard" <richard@webdezign.co.uk> writes:
> Hi git list,
>
> I'm trying to find out how to undo a merge.
When sitting on a merge commit,
  git reset --merge HEAD^

will undo this merge commit (i.e. pretend the merge has never occured, at least in your branch). Don't do that if you already published this merge commit.

> I know that my branches are independent and that I can just carry on
> working on them and merge again later, but I'm just trying to keep
> my revision graph tidier. Should I even be undoing merges?

If it's about cleaning up your history, "git rebase" is your friend, too (with the same limitation: don't do that on published history). By default, it does some kind of history flattening.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Richard· Dec 14, 2009, 11:45 UTC · re: Matthieu Moy · lore

RE: Undoing merges

Hi again Matt,
Thanks for the reply.
Show 11 quoted lines
> > Hi git list,
> >
> > I'm trying to find out how to undo a merge.
> 
> When sitting on a merge commit,
> 
>   git reset --merge HEAD^
> 
> will undo this merge commit (i.e. pretend the merge has never
> occurred, at least in your branch). Don't do that if you already
> published this merge commit.
The problem that I'm far past the merge commit.
Show 7 quoted lines
> > I know that my branches are independent and that I can just carry on
> > working on them and merge again later, but I'm just trying to keep
> > my revision graph tidier. Should I even be undoing merges?
> 
> If it's about cleaning up your history, "git rebase" is your friend,
> too (with the same limitation: don't do that on published history). By
> default, it does some kind of history flattening.

I had a look at the git-rebase man page and it showed to remove a commit from the middle of a range of commits. I think as I am on longer on the merge commit and cannot use "git reset --merge HEAD^", I can rebase all the commits from the commit just after the merge onto the commit just before the merge and that will remove the merge. Unfortunately I didn't get a change to try that out so I don't know whether it will work or not.

Richard

← back to recent threads