Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run git diff on a file that has moved

Tags:

git

diff

Ok the scenario is as follows . . .

  1. Move a bunch of files under a new folder in GIT
  2. Now I want to view the commit history of one of those files
    • Normally a git log filename would suffice
    • Since the file has been moved I can achieve this with git log--follow filename
  3. The --follow commands gives me the full history but I unfortunately I am unable to compare two SHAs in this history for a particular file

For example, I can run a git diff SHA1 SHA2: This will return all the file changes made between these commits.

However, if I try to bring it down to the file level to compare (git diff SHA1 SHA2 filename) it returns nothing !

(Although the previous diff of the SHAs show changes within this file)

Has Anyone come across this before ..

I understand that between the commits this file has moved so I have tried variations like

git diff --follow SHA1 SHA2 filename

to no avail.

Has anyone else experienced this and if so, do they have a solution to it ?

like image 391
user2339060 Avatar asked Oct 03 '22 20:10

user2339060


1 Answers

Another option worth looking into is -M. However, in the likely case that this doesn't help, either, you can manually tell git the correct file paths like this:

git diff SHA1:path/to/file1 SHA2:path/to/file2

(The paths need to be relative to the top level of the repo)

like image 104
Jan Krüger Avatar answered Oct 07 '22 16:10

Jan Krüger