How to diff one file to an arbitrary version in Git?

git diff <revision> <path>

For example:

git diff b0d14a4 foobar.txt

If you want to see the difference between the last commit of a single file you can do:

git log -p -1 filename

This will give you the diff of the file in git, is not comparing your local file.


To see what was changed in a file in the last commit:

git diff HEAD~1 path/to/file

You can change the number (~1) to the n-th commit which you want to diff with.


You can do:

git diff master~20:pom.xml pom.xml

... to compare your current pom.xml to the one from master 20 revisions ago through the first parent. You can replace master~20, of course, with the object name (SHA1sum) of a commit or any of the many other ways of specifying a revision.

Note that this is actually comparing the old pom.xml to the version in your working tree, not the version committed in master. If you want that, then you can do the following instead:

git diff master~20:pom.xml master:pom.xml

Tags:

Git

Diff

Git Diff