If I found a bug in my application, sometimes I need to know which commits have affected to the bug source code line. I'm wondering which is the best approach to do it with Git.
The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.
Git doesn't record the last modification date, only the commit/author dates for a all commit (which can include more than one file). You would need to run a script in order to amend a commit with the last modification date of a particular file (not very useful if said commit has more than one file in it).
Summary. The git blame command is used to examine the contents of a file line by line and see when each line was last modified and who the author of the modifications was.
To see commits affecting line 40 of file foo:
git blame -L 40,+1 foo
The +1 means exactly one line. To see changes for lines 40-60, it's:
git blame -L 40,+21 foo
OR
git blame -L 40,60 foo
The second number can be an offset designated with a '+', or a line number. git blame docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With