Git diff HEAD ^ HEAD <filename> does not display anything

I am trying to show the difference between the last commit and the previous:

 git diff HEAD^ HEAD <filename> 

but it doesn’t display anything. I know that there is a difference between the two commits.

What am I doing wrong and how to fix it?

PS: I feel that this has been discussed many times, but for some reason cannot find a useful link.

+2
source share
2 answers

It does not display anything if this file has no changes between HEAD^ and HEAD .

Please note that with git1.8.5 + you can do:

 git diff @^ -- afile 

( @ means HEAD )


git log -p -- aFile will provide all SHA1 changes for this file.
( -p to display diff)


To see the latest file modification (without having to deal with HEAD or another SHA1):

 git log -1 -p -- aFile 
+4
source

The changes you made to HEAD in a particular file are obviously missing from HEAD ^, otherwise it will not be part of the commit at all.

The command to view these changes is: git show HEAD -- <filename>

0
source

Source: https://habr.com/ru/post/1244575/


All Articles