By default, information about the original cherry commit is not recorded as part of the new commit.
Record source commit in ad
If you can force the use of certain workflows / options, git cherry-pick has the -x option:
When recording a commit, add a note to the original commit message indicating which of these changes was selected from the cherry.
This is obviously useless if you cannot rely on cherry pickers using this option. Also, since the recorded information is plain text and not the actual link to Git, even if you use -x , you still need to take steps to make sure the original commit is saved (for example, is part of a DAG tag or branch without rewinding )
git cherry and git patch-id
If you can limit your search to two separate branches of the DAG history, then git cherry can find both "unpicked" and "selected" cherries.
Note This command (and its associated git patch identifier ) can only identify conflicting cherries that were individually selected without further changes. If there is a conflict when you select a cherry (for example, you needed to slightly change it to make it apply), or you used -n / --no-commit to make additional changes (for example, several cherries in one commit) or the contents of the commit were rewritten after selection, then you would have to rely on comparing commit messages (or -x information if it was written).
git Cherry is not intended to determine the origin of the collected cherries, but we can use it a little to identify individual cherry pairs.
Given the following DAG story (as in the example with the original posters):
1
you will see something like this:
% git cherry master dev + A - C % git cherry dev master + B - D
(A, B, C, and D are full SHA-1 hashes in real output)
Since in each list we see one cherry (lines - ), they should form a cherry pair. D was a cherry selected from C (or vice versa, you cannot tell only with DAG, although commit dates may help).
If you are dealing with more than one potential cherry, you will need to “minimize your” program to make a comparison. The code should be simple in any language with associative arrays, hashes, dictionaries, or equivalent. In awk, it might look like this:
match_cherries() { a="$(git rev-parse --verify "$1")" && b="$(git rev-parse --verify "$2")" && git rev-list "$a...$b" | xargs git show | git patch-id | awk ' { p[$1] = p[$1] " " $2 } END { for (i in p) { l=length(p[i]) if (l>41) print substr(p[i],2,l-1) } }' } match_cherries master dev
In an extended example, in which there are two collected cherries:
1
The result may look like this:
match_cherries master dev DC EA
(A, C, D, and E are full SHA-1 hashes in real output)
This tells us that C and D represent the same change and that E and A represent the same change. As before, there is no way to determine which of each pair was “first” if you do not take into account (for example) the fixation dates of each commit.
Control Message Comparison
If your cherries were not selected with -x , or they are dirty (had conflicts or other changes added to them (i.e. using --no-commit plus additional changes or using git commit --amend or another “rewriting history”)), then you may have to abandon a less reliable method for comparing commit messages.
This method works best if you can find a commit message bit that is likely to be unique to the commit, and is unlikely to change in the commit resulting from the cherry pick. The bit that will work best will depend on the style of commit messages used in your project.
Once you have chosen the "identification part" of the message, you can use git log to find commits (also shown in Jeffries' Answer).
git log --grep='unique part of the commit message' dev...master
The --grep argument is actually a regular expression, so you may need to avoid any regular expression metacharacters ( []*?.\ ).
If you are not sure which branches might contain the original commit and the new commit, you can use --all , as Jefromi showed.