Is there a shorthand for identifying the last commit common to two branches? For example if I have master and then topic1 splits off from master, and they both continue
master:
a------b------c------d
\
topic1: r------s------t
Is there a way to identify say b
?
For example if there was such a thing as master#topic1 (same as topic1#master) that meant, "the most recent commit shared by both master and topic."
I would like to be able to:
$ git checkout topic1
$ git diff master#topic1..topic1
I know that I can do:
git diff master..topic
but I don't care about commits c
and d
.
The answer to the question you're actually asking:
git diff master...topic
Note the three dots.
From the manpage:
git diff [--options] <commit>...<commit> [--] [<path>...]
This form is to view the changes on the branch containing and up to the second , starting at a common ancestor of both
<commit>
.git diff A...B
is equivalent togit diff $(git merge-base A B) B
. You can omit any one of<commit>
, which has the same effect as usingHEAD
instead.
use git merge-base
.
NAME
git-merge-base - Find as good common ancestors as possible for a merge
SYNOPSIS
git merge-base [-a|--all] [--octopus] <commit> <commit>…
git merge-base --independent <commit>…
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With