‘git diff’ doesn’t show enough

The important thing to realize about git diff A B is that it only ever shows you the difference between the states of the tree between exactly two points in the commit graph – it doesn’t care about the history. The .. and ... notations used for git diff have the following meanings:

An illustration of the different ways of specifying commits for 'git diff'

So when you run git diff master feature that’s not just showing you the change introduced by the commit you’ve marked as 2 – the output should show the exact differences between the state of the tree committed in master and the state of the tree committed in feature. If it’s not showing you the earlier changes on your feature branch, perhaps you resolved conflicts from the earlier merges from master in favour of the version in master?

As cebewee says, it may be that what you want is git log -p master..feature, since git log does care about history. The meaning of .. and ... for git log are different since they select a range of commits:

An illustration of the different ways of specifying ranges of commits for git log

Incidentally, it’s often said that merging from master into a topic branch is the wrong thing to do – instead you should be rebasing, or merging your topic branch into master after it is complete. This keeps the meaning of the topic branch easily understood. The Git maintainer did a (somewhat difficult to understand) blog post about the philosophy of merging which discusses that.

Leave a Comment