Ivan
Ivan

Reputation: 15922

Git: Who has modified this line?

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.

Upvotes: 67

Views: 37686

Answers (5)

Nayagam
Nayagam

Reputation: 1875

You can use

git annotate filename (or)

git blame filename

Upvotes: 2

vcsjones
vcsjones

Reputation: 141638

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

Upvotes: 43

ahaurat
ahaurat

Reputation: 4245

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

Upvotes: 68

Seth Robertson
Seth Robertson

Reputation: 31451

git blame filename

is the best command to show you this info

Upvotes: 9

Frank Schmitt
Frank Schmitt

Reputation: 30775

If you only need the last change:

git blame

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

git bisect

Upvotes: 9

Related Questions