我想显示文件中一行的更改日志。问题是命令 git log {commitHash} -p -1 -L 17,+1:{filePath} 向我提供了 {commitHash} 之后第 17 行的历史记录。我想要的是以前第 17 行的变更日志。
我查看了文件,发现在提交之后第 17 行现在是第 20-22 行。所以我尝试了 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>
我想要的基本上是一个命令,我在其中提供第 17 行,+1 但得到 git log {commitHash} -p -1 -L 20,+3:{filePath} 的结果命令。
最佳答案
您似乎想根据基线编号从 git diff
输出中抓取 block 。
这里有一些丑陋的 perl 可以做到这一点。
git diff -U0 d462a1f6 e627666c | perl -e 'while(my $line = <>){ if($line =~ /^@@ -14/) { while($line = <>) { if($line =~ /^@@/) {exit} print $line} } }'
这对我在 Windows 上使用 git bash 没问题。
您当然希望将示例中的“14”替换为所需的行号。
您还可以过滤输出以仅显示添加的行并进行小的更改,例如
print $line if $line =~/\+/
关于git - 显示以前线路的变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55844797/