5

git log --follow <myfile> shows the git log for one file.

I'd like to see this log with all the changes (diffs) in this file. I try:

git log --full-diff --follow <myfile>

But this fails with:

fatal: --follow requires exactly one pathspec

Why? How can I get the diff I wanted?

Or maybe, is it a bug in git?

mik01aj
  • 11,928
  • 15
  • 76
  • 119

2 Answers2

3

You can get it like this:

git diff <file_path_relative_to_project_root>

Edited:

Explanation: Took a while to understand this. Whenever git log -p <file> is used it shows the commits where ever the file was touched and diffs for the same file alone. That means if you want to follow the complete history of a file you can add --follow option and get to see the complete history.

But when you enter this command: git log --full-diff -p file , it shows you all the commits where ever this file was touched plus now it not only shows diff for the specified file but also shows the diff's for all the files that were touched in the commit. That means its giving you result for multiple files.

If you try this command: git log help You'll see that --follow option can only be used only for a single file so you can have a command like this: git log --follow -p file since it shows results for only single file.

But it cannot be used with the following command: git log --full-diff --follow -p file as it shows results for multiple files and this query would result in an error.

Sahil
  • 3,338
  • 1
  • 21
  • 43
  • No. Git diff can show me only changes between 2 states of the file (by default: the file from repo HEAD and the file from disk), but not the full history. – mik01aj Aug 05 '15 at 13:30
  • 1
    You'll find your answer [here](http://stackoverflow.com/a/5493663/3863146) i.e. **git log --follow -p -- file** – Sahil Aug 05 '15 at 13:35
  • Thanks, this works! So you answered my second question :) How about the explanation for the "why"? – mik01aj Aug 05 '15 at 15:00
  • Please find the answer above, I have edited it for the why part. Let me know if you have any doubt. – Sahil Aug 06 '15 at 01:16
3

TL;DR version of Sahil's answer:

In git log, --full-diff doesn't work with --follow, because "full" means "show all changed files", and --follow works only with one file.

Solution: use git log --follow -p <file>.

mik01aj
  • 11,928
  • 15
  • 76
  • 119