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

Re: got myself into trouble; now what? - how to revert once you've pushed

From
Jeff King <peff@peff.net>
Date
Mar 1, 2011, 19:50 UTC
Message-ID
<20110301195027.GE10082@sigill.intra.peff.net>
In-Reply-To
<AANLkTi=RGhGMcoDEL4q2pnnZ97tdswYG7OkjNS3wF7jn@mail.gmail.com>
On Tue, Mar 01, 2011 at 02:37:19PM -0500, Robert Buck wrote:
Show 5 quoted lines
> We have two branches: master, feature/wixinstall
> 
> Apparently a merge happened from the branch to master (and I am pretty
> sure I never typed `git merge...`). But alas, a merge somehow happened
> and got pushed.
Did you run "git pull", which is basically fetch+merge?
Show 9 quoted lines
> Then I followed the Git Pro documentation, which said to do this...
> 
>     git revert -m 1 [sha_of_C8]
> 
> Now I am left with a bigger mess. When I merge master to the branch,
> all the newly added files on the branch got deleted (not what I
> wanted). Somehow git is interpreting the revert literally as a
> sequence of deletes which it incorrectly then applies to the work on
> the branch.

Yeah. That reverts the merge, in essence creating a new tree built on top of the merge without the results of the merge. But when you try to re-merge between those two branches, it sees that history has already combined, and then afterwards eliminated the result. Which is not what you wanted.

Read the section "reverting the revert" directly below the advice you followed:

  http://progit.org/2010/03/02/undoing-merges.html
Show 5 quoted lines
> What I really wanted the revert to do is restore the history of the
> world immediately prior to the merge. But now I have a branch I can't
> merge into at all without losing a weeks work.
> 
> How can I get out of this mess?

If you can accept that history will be rewritten (which is a problem if people have built on top of your bogus merge), then what you want is:

  git checkout master
  git reset --hard $SHA1_OF_MERGE^
and then re-push.
-Peff
Previous: Robert BuckNext: Robert Buck
Message 2 of 5 in “got myself into trouble; now what? - how to revert once you've pushed”
  1. Robert BuckMar 1, 2011
  2. Jeff KingMar 1, 2011
  3. Robert BuckMar 2, 2011
  4. Jeff KingMar 2, 2011
  5. Jon SeymourMar 2, 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.