Git: Who has modified this line?

Git

Git Problem Overview


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.

Git Solutions


Solution 1 - Git

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

Solution 2 - Git

I'd use the git blame command. That's pretty much exactly what it is for. The documentation should get you started.

Solution 3 - Git

git blame filename

is the best command to show you this info

Solution 4 - Git

If you only need the last change:

git blame

Otherwise, you could try to automatically find the offending change with

git bisect

Solution 5 - Git

You can use

git annotate filename (or)

git blame filename

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIvanView Question on Stackoverflow
Solution 1 - GitahauratView Answer on Stackoverflow
Solution 2 - GitvcsjonesView Answer on Stackoverflow
Solution 3 - GitSeth RobertsonView Answer on Stackoverflow
Solution 4 - GitFrank SchmittView Answer on Stackoverflow
Solution 5 - GitNayagamView Answer on Stackoverflow