19

Is there a way to determine if a commit is cherry-picked in and which origin commit the changes cherry-picked from?

git cherry-pick -x is a solution to record the information when I do the cherry-pick. But if we didn't use the -x option, are there any other solutions?

Michael
  • 8,362
  • 6
  • 61
  • 88
atiking
  • 933
  • 2
  • 9
  • 13
  • Seems a duplicate of https://stackoverflow.com/questions/2922652/git-is-there-a-way-to-figure-out-where-a-commit-was-cherry-picked-from, which has the same answer in more detail. – Francesco Dondi Oct 08 '20 at 11:02

1 Answers1

14

Git provides

git cherry

git log --cherry

both of which at a low level use git patch-id to determine when it thinks changes have been cherry picked. Those commands will virtually never have false positives, but they may have false negatives.

ruffin
  • 16,507
  • 9
  • 88
  • 138
Andrew C
  • 13,845
  • 6
  • 50
  • 57
  • What would cause commits that were *not* cherry-picked by SHA to appear in your `git log --cherry` results? That is, if they aren't false positives, is there another way that git would consider a commit to be a cherry pick other than being an explicitly referenced SHA in a `git cherry-pick [SHA]` command? – ruffin Sep 25 '17 at 18:48
  • @ruffin - if it was a trivial change and two people made it identically then you'd have a match as well. It wouldn't really be a false positive since the change is the same. – Andrew C Sep 26 '17 at 13:03
  • Interesting that git catches that so easily -- looks like we do that a fair amount, though they do all seem to be smallish changes. Wonder if changes are happening in more than one feature branch, then being merged up from different sources that share those same edits -- that is, it looks like "unofficial cherry picking" is going on where "the *same* person made an edit identically in two branches" rather than "two people" ... (◔_◔) Thanks. – ruffin Sep 26 '17 at 14:32
  • `git-cherry - Find commits yet to be applied to upstream` The description and functionality are a bit inverted. This can be a somewhat confusing command. – Abandoned Cart Aug 04 '18 at 15:08