Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show history of commits for a line or section in a file

Tags:

git

I'm looking to step through the history of commits for a section in a file. Particularly, there are two lines I'm interested in. I want to see what changes were made to these two lines going back to a few months ago, or even the origin of the file. Is there a quick way to get the changes using the command line? I know there are GUI's for git that allow you to do this, but I'd prefer not to. I'd rather use vim or sublime if I'm going to do that.

Ideally I want something like the commit hash, date, name, and change.

34hi5u3k 4/13/2013 Someone Name (Line 408)  $text = 'Something';
72wbedfj 4/05/2013 Someone Else (Line 408)  $text = 'Something else';
827y3hrj 3/29/2013 Someone Nice (Line 408)  $text = 'This one time...';
like image 490
thepriebe Avatar asked Nov 11 '22 11:11

thepriebe


1 Answers

Show all changes to lines 95-105 in $filename:

git log -L 95,105:$filename

Show all changes to 10 lines starting at regex in $filename:

git log -L /<regex>/,+10:$filename

The output produced is not in the ideal format you mentioned, but it does show all diffs for the specified section for the entire history.

like image 104
timcour Avatar answered Nov 15 '22 06:11

timcour