Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git: Who has modified this line?

Tags:

git

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.

like image 472
Ivan Avatar asked May 26 '11 19:05

Ivan


People also ask

How do I see who changed a file in 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.

How do you check who last modified a file in git?

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).

Which command will let you know who modified a file?

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.


1 Answers

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

like image 177
ahaurat Avatar answered Oct 08 '22 13:10

ahaurat