How do I check if a single commit has already been applied to a specific branch?
Using the documentation of git-cherry
as an example:
$ git log --graph --oneline --decorate --boundary origin/master...topic
* 7654321 (origin/master) upstream tip commit
[... snip some other commits ...]
* cccc111 cherry-pick of C
* aaaa111 cherry-pick of A
[... snip a lot more that has happened ...]
| * cccc000 (topic) commit C
| * bbbb000 commit B
| * aaaa000 commit A
|/
o 1234567 branch point
$ git cherry origin/master topic
- cccc000... commit C
+ bbbb000... commit B
- aaaa000... commit A
How would I know that cccc000
has the same content as - cccc111
without having to process the whole tree? Is this possible?
Notice that git-cherry
relies on the patch content (diff) and this is key to the question.
git log
has a --cherry-mark
option which adds information on symmetric differences (a.k.a "3-dots operator" A...B
)
Try running :
git log --oneline --graph --boundary --cherry-mark master...topic
You should see unique commits prefixed with +
(or *
when the --graph
option is on), and commits present on both sides prefixed with =
.
If you want to know how commits are matched : git patch-id
computes the result used by cherry-pick / rebase.
git patch-id
expects a patch (as produced by git show
or git diff
) on STDIN :
$ git show <commit-ish> | git patch-id
<hash for patch> <hash of input revision, if it can determine a revision>
For example : you can view the patch-id
s of all individual commits in A...B
:
git rev-list origin/master...forkpoint | while read sha1; do
git show $sha1 | git patch-id
done
You can use this result in a script, to print more explicitly how commits are linked.