git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: how to undo a git merge?

From
SRSverre Rabbelier <alturin@gmail.com>
Date
Jul 11, 2008, 18:55 UTC
Message-ID
<bd6139dc0807111155x46a9f6acnf2d585f62342f4a6@mail.gmail.com>
In-Reply-To
<fa7d16350807111146m18b0ca9q6902c2167bfd3512@mail.gmail.com>
On Fri, Jul 11, 2008 at 8:46 PM, ff <ff@member.org> wrote:
Show 7 quoted lines
>> 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
Previous: Miklos VajnaNext: Jakub Narebski
Message 7 of 8 in “how to undo a git merge?”
  1. ffJul 11, 2008
  2. Miklos VajnaJul 11, 2008
  3. Jakub NarebskiJul 11, 2008
  4. Miklos VajnaJul 11, 2008
  5. ffJul 11, 2008
  6. Miklos VajnaJul 11, 2008
  7. Sverre RabbelierJul 11, 2008
  8. Jakub NarebskiJul 11, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.