git – How to diff changed files versus previous versions after a pull?


When I run “git pull” I often want to know what changed between the last version of a file and the new one. Say I want to know what someone else committed to a particular file.

How is that done?

I’m assuming it’s “git diff” with some parameters for commit x versus commit y but I can’t seem to get the syntax. I also find “git log” confusing a bit and am not sure where to get the commit ID of my latest version of the file versus the new one.


There are all kinds of wonderful ways to specify commits – see the specifying revisions section of man git-rev-parse for more details. In this case, you probably want:

The @{1} means “the previous position of the ref I’ve specified”, so that evaluates to what you had checked out previously – just before the pull. You can tack HEAD on the end there if you also have some changes in your work tree and you don’t want to see the diffs for them.

I’m not sure what you’re asking for with “the commit ID of my latest version of the file” – the commit “ID” (SHA1 hash) is that 40-character hex right at the top of every entry in the output of git log. It’s the hash for the entire commit, not for a given file. You don’t really ever need more – if you want to diff just one file across the pull, do

This is a general thing – if you want to know about the state of a file in a given commit, you specify the commit and the file, not an ID/hash specific to the file.

Leave a Reply