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
Jon Seymour <jon.seymour@gmail.com>
Date
Mar 2, 2011, 15:52 UTC
Message-ID
<AANLkTi=Oiu19R8+hX16gWDghkPkYf12731KkYctwQgEG@mail.gmail.com>
In-Reply-To
<20110302133720.GA26989@sigill.intra.peff.net>

Here's the approach I take to backout a merge with a bogus topic branch. I use this in a large team environment where backtracking the shared integration branch is simply not an option.

Suppose a topic branch 'topic' was merged with master to produce a merge and then it was decided that topic was a little half-baked

e.g.

$> git merge topic #1 $> git tag M

$> git checkout -b deliver-topic M^2 $> git diff --full-index M M^1 | git apply --index # should work if #1 did not produce a conflict $> git git commit -m "backout premature delivery of topic" $> git checkout master $> git merge deliver-topic # backouts changes contributed by #1

This assumes that neither the original merge with bogus or the merge with deliver-topic produce any conflicts.

Then, suppose I fix the original problem with the topic branch by making additional commits to the original topic branch that fix the problem.

I then revert the revert on the deliver-topic branch

$> git checkout deliver-topic $> git revert # revert the backout to restore the deliver-topic to the same state as the original topic $> git merge topic # this is the fixed topic $> git checkout master $> git merge deliver-topic

The nice thing about using a separate delivery branch to manage the backouts of prematurely merged topics is that the topic branch itself stays clean. All the revert and apply logic is confined to a delivery branch which can be forgotten about once the history moves on. Yes, the integration branch itself looks a little messy, but integration branches tend to a look a little messy anyway.

jon.
Previous: Jeff King
Message 5 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.