2

When a file name or path changes, git status doesn't tell me that there is a modified file, it tells me that there is a deleted file and a created file. git diff shows me all the content of the previous version of the file, and doesn't show me the new content (since it's a new file).

Is it possible to see the changes in a file which name or path has changed?

papillon
  • 1,807
  • 2
  • 19
  • 39
  • To avoid two seperate git status messages, you can use `git mv` instead the normal `mv` to rename files. Then git will know that the file was renamed. – YesThatIsMyName May 15 '19 at 13:07

2 Answers2

3

Yes, add both the deleted and created file and then run a diff on the index:

git add oldname newname
git diff --cached oldname newname

If the files are too different, the diff will show them separately, otherwise will show them as a single file updated (with a new name, and some updated content).

Also, as @YesThatIsMyName mentioned, you can do the file renaming in Git directly using git mv oldname newname to not have to run git add oldname newname after having moved them.

padawin
  • 4,230
  • 15
  • 19
1

You can use --follow switch with git log. It will show a history of the changes committed, even after renames.

git log --follow renamedfile.cs

For more info, see here.

Also, see this interesting related question here.

Donal
  • 31,121
  • 10
  • 63
  • 72