If you are in a git branch and want to see all commits since the branch point you can use this one-liner.
git diff $(git merge-base master HEAD)
For example, with the following topology, the merge base between
o---o---o---branch / ---o---1---o---o---o---master
There are a lot of hidden details in this compact command, so let’s analyze it in detail. The long form is:
git diff $(git merge-base $(git rev-parse master) $(git rev-parse HEAD))..HEAD
Let’s look at this from the inside out:
git rev-parse masterprints the SHA-1 of the latest commit in the
git rev-parse HEADprints the SHA-1 of the latest commit in the current branch.
git merge-base <commit1> <commit2>finds the common ancestor of the two commits.
git diff <commit1>..<commit2>shows the changes between the two commits.
There are various ways to make this more compact. In
git merge-base, you can just use
master to mean
git rev-parse master, and
HEAD to mean
git rev-parse HEAD.
git diff <commit1>..<commit2>, the default for
HEAD. If only
<commit1> is given,
..HEAD is assumed.