Ahmed
Ahmed

Reputation: 15069

How to find a specific change in a specific file in Git

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.

Upvotes: 13

Views: 8632

Answers (3)

andreav
andreav

Reputation: 567

You could try:

git log --all -S oldvalue filename

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

Upvotes: 17

Paul Beckingham
Paul Beckingham

Reputation: 14925

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.

Upvotes: 5

pjmorse
pjmorse

Reputation: 9304

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.

Upvotes: 14

Related Questions