12

I have a file in a Git project that had a specific value changed at some point by someone; I don't know who or when. I want to find when the change was made, but I'm not sure how I can track that in Git.

I've tried using git diff <sha1> <sha2>, but that shows the differences for the entire project, while I want to check one particular file.

Charles
  • 50,943
  • 13
  • 104
  • 142
Ahmed
  • 14,503
  • 22
  • 92
  • 150
  • You can find it [here][1]. Also, you can read the official git docs. [1]: http://stackoverflow.com/questions/5586383/how-to-diff-one-file-to-an-arbitrary-version-in-git – Luis Andrés García Jan 09 '13 at 13:58
  • @Luis: The only link syntax that works in SO comments is `[Link text](URL)`, or raw URLs. – me_and Jan 10 '13 at 11:37

3 Answers3

16

You could try:

git log --all -S oldvalue filename

This will list all commits where "oldvalue" changes (added or deleted)

pjmorse
  • 9,204
  • 9
  • 54
  • 124
andreav
  • 541
  • 5
  • 18
  • This worked perfectly for me. The issue in my case was that the particular line had been changed many times and git blame wasn't able to solve it for me as that included information on just the last change. Thanks! – saurabhj Oct 01 '19 at 09:52
13

git blame should help you. git blame <file> will show you <file>, line by line, and include on each line which user last changed that line, and in which commit.

pjmorse
  • 9,204
  • 9
  • 54
  • 124
5

In addition to git blame you can also use the command you have, but add a file name:

git diff <commit> <commit> <file>

That will show you diffs between the two commits, for a single file.

Paul Beckingham
  • 14,495
  • 5
  • 33
  • 67