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

Re: [RFC] Second parent for reverts

From
Junio C Hamano <junkio@cox.net>
Date
May 9, 2007, 21:54 UTC
Message-ID
<7v7irhslx1.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0705091406350.18541@iabervon.org>
Daniel Barkalow <barkalow@iabervon.org> writes:
Show 31 quoted lines
> The discussion about having a header to specify, for a revert commit, what 
> it reverts made me realize that this header *would* be useful, but that we 
> don't need a *new* header for it. I think that the right method is to add 
> the parent of the reverted commit as a second parent for the revert.
>
> If you have:
>
> a -> b -> c -> d
>
> And you want to revert b, the most exact flow would be:
>
> a -> b -> c -> d -> e
>        \         /
>         -> a' ---
>
> I.e., you exactly remove the effects of b to generate a commit that has 
> the same tree as a, and then you merge.
>
> But a' doesn't actually take anything from b, since it's reverting all of 
> b (unless it's only reverting part of b), and, if b isn't there, it 
> doesn't need a commit message, either, so it's not different from a. So 
> the flow should be:
>
> a -> b -> c -> d -> e
>   \              /
>    --------------
>
> And this means blame work correctly: lines that b changed will be blamed 
> on a (or an ancestor), because e will match a there and be different from 
> d. So I think git-revert should simply add in the reverted patch's parent. 
> Does this analysis make sense to other people?

The revert operation at the tree level (not commit level) treats AS IF b is a common ancestor between a and d and computes a merge between a and d using that fake common ancestor to reach at e. So it is understandable that you are confused that the result somehow has something to do with a merge between a and d.

But other than that, the "analysis" does not make any sense to me.

When you have a merge commit somebody else made, you should be able to reproduce it yourself, with the help from the intent of the merge explained in the commit log of the merge commit (usually it says "I am merging this development line with that one"). With a->b->c->d history, what is the sane merge result between a and d? It won't be e. The only clue that you did a revert of b is contained in the message "Revert b", because b is not a common ancestor between a and d.

An interesting tangent is that you can revert both b and c with a single tree-level operation by pretending as if c is a common ancestor between a and d and run tree-level 3-way merge to apply difference between c and d on top of a to come up with e. It would not make sense to record neither one of a b c as the fake second parent.

I would suggest to leave a revert as a revert. It is not a merge.

In general, you should think of an act of making a commit (not limited to a merge but a single parent) to mean that you are making this statement:

	I have considered the development history that leads to
	the parent commits this commit records, and the tree
	recorded with this commit suits the purpose of my branch
	better than all of them.

Obviously, if you considered the history that leads to 'd', you have considered the hsitory that leads to 'a' as well, so recording both 'a' and 'd' as parents does not make much sense. You could have recorded 'e' as an Octopus of 'a', 'b', ... 'd', and the statement does not change.

Previous: Johan HerlandNext: Linus Torvalds
Message 5 of 53 in “[RFC] Second parent for reverts”
  1. Daniel BarkalowMay 9, 2007
  2. Johannes SchindelinMay 9, 2007
  3. Shawn O. PearceMay 9, 2007
  4. Johan HerlandMay 9, 2007
  5. Junio C HamanoMay 9, 2007
  6. Linus TorvaldsMay 9, 2007
  7. Linus TorvaldsMay 10, 2007
  8. Johan HerlandMay 10, 2007
  9. Linus TorvaldsMay 10, 2007
  10. 00/15 git-note: A mechanisim for providing free-form after-the-fact annotations on commitsJohan Herland, May 27, 2007
  11. 01/15 git-note: Add git-note command for adding/listing/deleting git notesJohan Herland, May 27, 2007
  12. 02/15 git-note: (Documentation) Add git-note manual pageJohan Herland, May 27, 2007
  13. 03/15 git-note: (Administrivia) Add git-note to Makefile, .gitignore, etc.Johan Herland, May 27, 2007
  14. 04/15 git-note: (Plumbing) Add plumbing-level support for git notesJohan Herland, May 27, 2007
  15. 05/15 git-note: (Plumbing) Add support for git notes to git-rev-parse and git-show-refJohan Herland, May 27, 2007
  16. 06/15 git-note: (Documentation) Explain the new '--notes' option to git-rev-parse and git-show-refJohan Herland, May 27, 2007
  17. 07/15 git-note: (Almost plumbing) Add support for git notes to git-pack-refs and git-fsckJohan Herland, May 27, 2007
  18. 08/15 git-note: (Decorations) Add note decorations to "git-{log,show,whatchanged} --decorate"Johan Herland, May 27, 2007
  19. 09/15 git-note: (Documentation) Explain new behaviour of --decorate in git-{log,show,whatchanged}Johan Herland, May 27, 2007
  20. 10/15 git-note: (Transfer) Teach git-clone how to clone notesJohan Herland, May 27, 2007
  21. 11/15 git-note: (Transfer) Teach git-fetch to auto-follow notesJohan Herland, May 27, 2007
  22. 12/15 git-note: (Transfer) Teach git-push to push notes when --all or --notes is givenJohan Herland, May 27, 2007
  23. 13/15 git-note: (Documentation) Explain the new --notes option to git-pushJohan Herland, May 27, 2007
  24. 14/15 git-note: (Tests) Add tests for git-note and associated functionalityJohan Herland, May 27, 2007
  25. 15/15 git-note: Add display of notes to gitkJohan Herland, May 27, 2007
  26. Junio C HamanoMay 27, 2007
  27. Johan HerlandMay 28, 2007
  28. Jakub NarebskiMay 28, 2007
  29. Linus TorvaldsMay 28, 2007
  30. Johan HerlandMay 28, 2007
  31. Linus TorvaldsMay 28, 2007
  32. Johan HerlandMay 28, 2007
  33. Linus TorvaldsMay 28, 2007
  34. Johan HerlandMay 28, 2007
  35. Junio C HamanoMay 28, 2007
  36. Shawn O. PearceMay 28, 2007
  37. Johannes SchindelinMay 28, 2007
  38. Linus TorvaldsMay 29, 2007
  39. Shawn O. PearceMay 29, 2007
  40. Jakub NarebskiMay 29, 2007
  41. Andy ParkinsMay 29, 2007
  42. Johannes SchindelinMay 29, 2007
  43. Johan HerlandMay 29, 2007
  44. Jeff KingMay 29, 2007
  45. Johan HerlandMay 29, 2007
  46. Junio C HamanoMay 28, 2007
  47. Shawn O. PearceMay 28, 2007
  48. Add fsck_verify_ref_to_tag_object() to verify that refname matches name stored in tag objectJohan Herland, May 28, 2007
  49. Michael S. TsirkinMay 28, 2007
  50. Michael S. TsirkinMay 28, 2007
  51. Johan HerlandMay 28, 2007
  52. Martin LanghoffMay 10, 2007
  53. Junio C HamanoMay 10, 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.