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

Re: [PATCH] Documentation: 'cherry' does not cope well with merges from upstream

From
Michael J Gruber <git@drmicha.warpmail.net>
Date
Jul 2, 2010, 07:46 UTC
Message-ID
<4C2D995D.2020708@drmicha.warpmail.net>
In-Reply-To
<20100701210919.GA4283@burratino>
Jonathan Nieder venit, vidit, dixit 01.07.2010 23:09:
> Although ‘git cherry’ is advertised simply to list commits from
> <topic> that have not been merged into <upstream>, internally it
> works by checking for patches in <upstream>..<topic> that do not
> match a patch in <topic>..<upstream>.  This is fast because there
...and it says so in the very first line of the manpage.
Show 9 quoted lines
> are not many patches to check, and it makes sense semantically
> since even if a new patch patches an old patch from <upstream>,
> it cannot be said to have been merged upstream unless it was
> applied there at some point after the <topic> and <upstream>
> branches diverged.
> 
> But.  If the <topic> branch later merges from <upstream>, it
> throws a spanner in the works and for such a history ‘git cherry’
> is not very useful at all.

I actually think I've reported this before, but I don't mind :) I keep (topic) branches for my git.git patches. git cherry is helpful here. When a patch is applied, I merge the corresponding commit (i.e. Junio's version) to my topic branch to mark it as applied and to have a nice way of comparing the applied version to the submitted one. At that point git cherry stops being useful.

Show 33 quoted lines
> 
> Example:
> 
>  o---o---F---X'---G---U [upstream]
>           \        \
>            X----Y---M---T [topic]
> 
> Suppose the author of the ‘topic’ branch starts from upstream
> commit F and makes a few changes.  One is applied upstream, and
> additionally there is some other useful upstream change, so he
> performs a merge to include the upstream updates into topic.
> The expected output from ‘cherry’ is:
> 
>  + T
>  + Y
>  - X
> 
> Consider the author of a different branch, also called ‘topic’, but
> this one starts from commit G.  Some infrastructure from an existing 
> branch is needed, so first she merges that.  Then she adds her own
> commit.  The expected output from ‘cherry’ is:
> 
>  + T
>  + Y
>  + X
> 
> since none of the new commits have been applied upstream since
> the fork point.
> 
> ‘cherry’ cannot distinguish between these two cases, in part because
> it does not distinguish between parents in a merge commit.
> 
> Add a BUGS section to explain the problem.
This is not a bug. git cherry works exactly as described.
At worst, it is a misfeature.

git cherry would be more useful if you could specify a "limit" which is an ancestor of "fork-point", not only descendants.

> 
> Thoughts?  Improvements?
Allow general "limit" :)
Show 13 quoted lines
> 
>  Documentation/git-cherry.txt |   15 +++++++++++++++
>  1 files changed, 15 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/git-cherry.txt b/Documentation/git-cherry.txt
> index fed115a..83e3bdc 100644
> --- a/Documentation/git-cherry.txt
> +++ b/Documentation/git-cherry.txt
> @@ -59,6 +59,21 @@ OPTIONS
>  <limit>::
>  	Do not report commits up to (and including) limit.
>  
> +BUGS
+DISCUSSION
> +----
> +'git cherry' does not cope well with merges from upstream on the
> +working branch.  Any commits after the original fork point and
...which is the wrong way round anyways ;)
Show 10 quoted lines
> +before the latest merge from upstream will be reported as not found
> +in <upstream>.
> +
> +                       ____*____*____*_____*__> <upstream>
> +                      /                     \
> +   original fork point                       \
> +                      \__+__+__+__+__+__+__+__*_> <head>
> +
> +While these commits are part of upstream..head, their upstream
> +counterparts are not in head..upstream.

git-cherry(1) never speaks about upstream..head nor head..upstream. It uses "fork-point", and a merge creates a new "fork-point", i.e. merge-base. I think it would be good to keep like that in order to avoid that very misunderstanding. In fact, git cherry is about left and right commits in upstream...head.

The second paragraph of "DESCRIPTION" may cause confusion when read without the first one, though.

Michael
Previous: Jonathan NiederNext: Jonathan Nieder
Message 11 of 13 in “git cherry not marking commits with equivalent upstream”
  1. Andrew PimlottJul 1, 2010
  2. Andrew PimlottJul 1, 2010
  3. Björn SteinbrinkJul 1, 2010
  4. Andrew PimlottJul 1, 2010
  5. Documentation: 'cherry' does not cope well with merges from upstreamJonathan Nieder, Jul 1, 2010
  6. Andrew PimlottJul 1, 2010
  7. Jonathan NiederJul 1, 2010
  8. Junio C HamanoJul 1, 2010
  9. Jonathan NiederJul 2, 2010
  10. Jonathan NiederJul 2, 2010
  11. Michael J GruberJul 2, 2010
  12. Jonathan NiederJul 2, 2010
  13. Michael J GruberJul 2, 2010

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.