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

Re: unmerging feature branches

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 23, 2007, 19:33 UTC
Message-ID
<7vir4x7hiu.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<alpine.LFD.0.999.0710230922240.30120@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> writes:
Show 15 quoted lines
> Now, that said, reverting the data is not that hard. There is not any 
> single-command "revert this arm of a merge", but on the other hand, git 
> can certainly help you.
>
> The way to do it is:
>
> 	# go back to just before the merge, create a "fixup" branch
> 	#
> 	git branch -b fixup M^
>
> 	# merge all of it again, *except* the branch you didn't want to 
> 	# merge (this example assumes that you had a four-way octopus 
> 	# merge, and you now want to turn it into a three-way with the
> 	# next-to-last parent skipped):
> ...

Desire to revert an octopus would, as you demonstrated, often be to revert only one arm, but I think allowing to revert a twohead merge should be trivial. If we define "reverting a merge" to always revert all arms, then this should suffice.

diff --git a/builtin-revert.c b/builtin-revert.c
index a655c8e..719e293 100644
--- a/builtin-revert.c
+++ b/builtin-revert.c
@@ -269,8 +269,8 @@ static int revert_or_cherry_pick(int argc, const char **argv)
 
 	if (!commit->parents)
 		die ("Cannot %s a root commit", me);
-	if (commit->parents->next)
-		die ("Cannot %s a multi-parent commit.", me);
+	if (action != REVERT && commit->parents->next)
+		die ("Cannot %s a merge commit.", me);
 	if (!(message = commit->buffer))
 		die ("Cannot get commit message for %s",
 				sha1_to_hex(commit->object.sha1));

Note that allowing cherry-pick by removing the above two lines
allow replaying the data of a merge similar to a squash merge.
Previous: Linus TorvaldsNext: Linus Torvalds
Message 14 of 16 in “unmerging feature branches”
  1. martin f krafftOct 23, 2007
  2. Matthieu MoyOct 23, 2007
  3. Linus TorvaldsOct 23, 2007
  4. martin f krafftOct 23, 2007
  5. Linus TorvaldsOct 23, 2007
  6. martin f krafftOct 23, 2007
  7. Linus TorvaldsOct 23, 2007
  8. martin f krafftOct 23, 2007
  9. Linus TorvaldsOct 23, 2007
  10. Linus TorvaldsOct 23, 2007
  11. Alejandro Martinez RuizOct 31, 2007
  12. martin f krafftOct 31, 2007
  13. Linus TorvaldsOct 31, 2007
  14. Junio C HamanoOct 23, 2007
  15. Linus TorvaldsOct 23, 2007
  16. revert/cherry-pick: work on merge commits as wellJunio C Hamano, Oct 23, 2007

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.