Reputation: 33
I´d like to display the change log of a line in a file. The problem is that the command git log {commitHash} -p -1 -L 17,+1:{filePath} gives me the history of what is line 17 after the {commitHash}. What I want is the changelog of what used to be Line 17.
I´ve looked at the file and saw that after the commit Line 17 is now Line 20-22. So I tried git log {commitHash} -p -1 -L 20,+3:{filePath} :
commit {commitHash}
Author: {author}
Date: {date}
{commitMessage}
diff --git a/{filePath} b/{filePath}
--- a/{filePath}
+++ b/{filePath}
@@ -17,1 +20,3 @@
- <button type="button" class="btn btn-info" tooltip="someTooltip" placement="bottom" disabled>
+ <button type="button" class="btn btn-info"
+ tooltip="someTooltip"
+ placement="bottom" disabled>
What I want is basicly a command where I provide Line 17,+1 but get the result of the git log {commitHash} -p -1 -L 20,+3:{filePath} command.
Related Question: Retrieve the commit log for a specific line in a file?
Upvotes: 3
Views: 171
Reputation: 6947
It appears that you want to grab hunks from a git diff
output based on the base line number.
Here is some ugly perl that can do that.
git diff -U0 d462a1f6 e627666c | perl -e 'while(my $line = <>){ if($line =~ /^@@ -14/) { while($line = <>) { if($line =~ /^@@/) {exit} print $line} } }'
This works ok for me using git bash on Windows.
You would of course want to replace the "14" in the example with the desired line number.
You can also filter the output to show only added lines with a small change like
print $line if $line =~/\+/
Upvotes: 1