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

Re: cherry picking and merge

From
Jakub Narębski <jnareb@gmail.com>
Date
Aug 6, 2014, 15:43 UTC
Message-ID
<53E24D07.9010105@gmail.com>
In-Reply-To
<40F24BA38E03454A9BA152F6AFDE56C4@PhilipOakley>
Philip Oakley wrote:
> From: "Mike Stump" <mikestump@comcast.net>
> Sent: Friday, August 01, 2014 11:24 PM
>> On Aug 1, 2014, at 12:01 PM, Jakub Narębski <jnareb@gmail.com> wrote:
Show 12 quoted lines
>>> It can work in Subversion because Subversion stores information about
>>> what was merged in (and this includes cherry-picks, or whatever it is
>>> named in svn) in svn:mergeinfo property. Git does not track what was
>>> merged in, instead it represent the history as the graph of revisions,
>>> and tracks merges (by storing that it came from two or more commits)
>>> and not merged-in information.
>>
>> So, as a dumb user that just wants it to work, I am unsympathetic to
>> the `but software is hard’ excuse.  I am aware that some bugs are
>> harder to fix than others.  svn took a long time to fix this bug, but
>> they did.  I can wait, the only question is, will it be a week, a
>> month, a year, or a decade.

Here Git and Subversion went in different directions, and use different mechanisms (merge tracking vs merged-on tracking). Both have their advantages and disadvantages.

git-merge (in the most usual case) depends only on three revisions: the revision you merge into (current branch, ours), the revision you are merging (merged branch, theirs), and merge base (common ancestor). We could have another merge strategy that examines contents of revisions to handle cherry-picks and reverts... but it would be more complicated, and much slower.

Show 5 quoted lines
>>> When merging Git uses only what is being merged and its common
>>> ancestor (3-point merge). It is simple, and simple works!!!
>>
>> I gave a solution for git using branches and it works just fine.  It
>> retains the simple 3-point merge as well.

It works for this simple case, but I think it has unfortunate potential to go silently wrong.

Also, it prevents fully removing (commits, not only refs) the branch you cherry-picked from. The commit you cherry picked may no longer be (or may no longer should be) in the repository.

Show 15 quoted lines
> At the moment there is no formal way for Git to record within the commit
> metadata the inclusion of the cherry-picked diff (the 'merge' of the fix).
>
> Thinking out of the box, the issue is that the commit parents list does
> not have a formal mechanism to allow the recording that the 'merged'
> change was the patch change from a specific commit fom somewhere else
> (which may be missing from the local repo).
>
> Perhaps it needs a style of merging-rebase where a second (last) parent
> is added but it isn't the straight <sha1>, but says 'patch-<sha1>', such
> that readers with the capability could check if that <sha1> history is
> present locally, and if so if it's correct, so that you can now 'track'
> your fixes between releases, and (hopefully) older Gits don't barf on
> that extra 'fake' parent. Somehow I suspect that older Git's would
> barf.. (not enough time to create and test such a fake commit).

Sometime ago there was long discussion about adding 'weak' references to commit object header.

Beside the problem of backward compatibility, there was also the problem of semantics of said reference - what does it mean? It should work as well for cherry-picks, for interactive rebase (maybe?), and for reverts (which are also a problem).

Also, this could be avoided by using feature branches and merging instead of committing to one branch and cherry-picking to other branches. Also, git-rerere is your friend... sometimes.

>>> Have you tried git-imerge?
>>
>> No, not yet.  I’m not as interested in using it, as I would like git
>> itself to just work.

Maybe this command would make it into git proper, though probably not written in Python (there was once merge strategy written in Python, but currently git does not depend on Python).

-- 
Jakub Narębski
Previous: Philip OakleyNext: Mike Stump
Message 38 of 43 in “cherry picking and merge”
  1. Mike StumpAug 1, 2014
  2. brian m. carlsonAug 1, 2014
  3. Jakub NarębskiAug 1, 2014
  4. Mike StumpAug 1, 2014
  5. Philip OakleyAug 1, 2014
  6. Mike StumpAug 1, 2014
  7. Philip OakleyAug 2, 2014
  8. Philip OakleyAug 2, 2014
  9. Sam VilainAug 1, 2014
  10. Mike StumpAug 1, 2014
  11. Nico WilliamsAug 1, 2014
  12. Alex DavidsonAug 2, 2014
  13. Mike StumpAug 6, 2014
  14. Rebase safely (Re: cherry picking and merge)Nico Williams, Aug 6, 2014
  15. Nico WilliamsAug 6, 2014
  16. Mike StumpAug 1, 2014
  17. Keller, Jacob EAug 21, 2014
  18. Keller, Jacob EAug 21, 2014
  19. Nico WilliamsAug 1, 2014
  20. Mike StumpAug 1, 2014
  21. Nico WilliamsAug 1, 2014
  22. Jonathan NiederAug 1, 2014
  23. Jonathan NiederAug 1, 2014
  24. Nico WilliamsAug 1, 2014
  25. Junio C HamanoAug 1, 2014
  26. Nico WilliamsAug 1, 2014
  27. Junio C HamanoAug 1, 2014
  28. Jakub NarębskiAug 6, 2014
  29. Nico WilliamsAug 6, 2014
  30. Junio C HamanoAug 6, 2014
  31. Junio C HamanoAug 6, 2014
  32. Mike StumpAug 1, 2014
  33. Mike StumpAug 1, 2014
  34. Jonathan NiederAug 1, 2014
  35. Fwd: cherry picking and mergeJakub Narębski, Aug 1, 2014
  36. Mike StumpAug 1, 2014
  37. Philip OakleyAug 2, 2014
  38. Jakub NarębskiAug 6, 2014
  39. Mike StumpAug 6, 2014
  40. Nico WilliamsAug 7, 2014
  41. Mike StumpAug 8, 2014
  42. Nico WilliamsAug 8, 2014
  43. Fwd: Rebase safely (Re: cherry picking and merge)Mike Stump, Aug 8, 2014

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.