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

confusion over git-cherry-pick, git-merge and git-cherry

From
KGKevin Green <kevin.t.green@morganstanley.com>
Date
Feb 24, 2010, 21:39 UTC
Message-ID
<20100224213923.GV14244@morganstanley.com>
Hi,
Given this scenario:
  Work is done over a series of commits on branch 'alpha'.  A commit is
  cherry-pick'd from 'alpha' onto branch 'beta'.  Later, branch 'alpha'
  is merged into branch 'beta', I'm seeing unexpected output from
  git-cherry.
  Here's what the history currently looks like:
                      B'-----M beta
                    /       /
               o---A---B---C alpha

I would expect git-cherry to recognize that B' has the same content as B and thus show me a '-' sign in front. Instead, I get the following output from 'git-cherry alpha beta'

  $ git cherry alpha beta
  + B'
The output of git-log looks like this (which is also unfortunate):
  $ git log --pretty=oneline
  M  Merge branch 'alpha' into beta
  B' change 2
  C  change 3
  B  change 2
  A  change 1
  o  initial commit
The output of git-patch-id for B and B' is identical.  

Can someone please explain to me why git-cherry doesn't notice that the duplicate commit has the same content? Shouldn't it? Shouldn't I get the following output:

  $ git cherry alpha beta
  - B'

that is, there exists a commit on beta that doesn't exist in alpha, but the content there is the same?

How do others deal with cherry-pick and merge combined together?

To give some further background on what I'm trying to do, I would like to prevent changes getting made in the beta branch that don't already exist in alpha. I'm enforcing this with a server side hook that does a git-cherry and checks if any of the lines start with a '+'. This works great until I allow changes to be cherry-picked from alpha. The first cherry-pick works, but then when the whole of alpha is later merged in, the hook fails to allow any subsequent push to 'beta'.

Thanks
--Kevin
Next: Thomas Rast
Message 1 of 2 in “confusion over git-cherry-pick, git-merge and git-cherry”
  1. Kevin GreenFeb 24, 2010
  2. Thomas RastFeb 24, 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.