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

Re: Undo a commit that is already pushed to central server and merged to several branches

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
Dec 7, 2011, 14:42 UTC
Message-ID
<CALkWK0k46HnWTHx3iYuWFUegTgZhAMShx9MT2E83QCmxrvZOxg@mail.gmail.com>
In-Reply-To
<4EDF74EC.6090504@fechner.net>
Hi Matthias,
Matthias Fechner wrote:
Show 7 quoted lines
> [...]
> I continued to work then on different branches and merged the bad master
> branch to all my other branches.
> [...]
>
> What I would like to do is move this bogus commit into a different branch
> and remove all changes from this bogus commit from every branch.
If I understand correctly, each of your branches looks like*:
o  <--- HEAD of branch; merge commit referencing bogus commit
| \
o  \   <--- This is where you want to move the HEAD to
|   \
o    o  <-- Bogus commit from master branch
|
o
|
o  <-- Branch born

Assuming that you actually want to rewrite the history, the situation calls for a git-reset(1). Just "git reset --hard HEAD~1" on each of your branches (Caution: first understand what it does!) and you'll rewind the HEAD to "undo" the bad merge. After that you can just "git push +foo:foo" to overwrite the foo branch on your server. If you don't want to rewrite anything and simply commit the inverse of the bad commit, see git-revert(1).

* If you're having difficulty understanding the diagram, please read:
http://eagain.net/articles/git-for-computer-scientists/
Cheers.
-- Ram
Previous: Matthias FechnerNext: Matthias Fechner
Message 2 of 6 in “Undo a commit that is already pushed to central server and merged to several branches”
  1. Matthias FechnerDec 7, 2011
  2. Ramkumar RamachandraDec 7, 2011
  3. Matthias FechnerDec 7, 2011
  4. Ramkumar RamachandraDec 7, 2011
  5. Johan HerlandDec 7, 2011
  6. Matthias FechnerDec 8, 2011

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.