How to find a specific change in a specific file in Git
Asked Answered
U

3

13

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.

Uphemia answered 9/1, 2013 at 13:56 Comment(2)
You can find it [here][1]. Also, you can read the official git docs. [1]: #5586883Gomer
@Luis: The only link syntax that works in SO comments is [Link text](URL), or raw URLs.Corbel
C
17

You could try:

git log --all -S oldvalue filename

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

Ciborium answered 10/1, 2013 at 12:57 Comment(1)
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!Misgiving
Z
14

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.

Zizith answered 9/1, 2013 at 13:58 Comment(0)
C
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.

Conservatory answered 9/1, 2013 at 14:18 Comment(2)
The command executes without error and shows nothing , I am not sure whyUphemia
That would mean that <file> had no changes between the two commits.Conservatory

© 2022 - 2024 — McMap. All rights reserved.