git - 显示以前线路的变化

标签 git

我想显示文件中一行的更改日志。问题是命令 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} 的结果命令。

相关问题:Retrieve the commit log for a specific line in a file?

最佳答案

您似乎想根据基线编号从 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/

相关文章:

git - 如何用 git subtree merge 替换 svn 子目录供应商分支

c# - 使用预留IP Azure 构建失败

Git fatal error : unable to stat '*' : No such file or directory

xcode - xCode中的ios git merge 冲突

git - 在以前的提交中表示 Git merge (假 merge )

来自提交哈希的 GitHub pull 请求 ID

javascript - 有没有办法用 Lerna "refresh"导入存储库?

node.js - 将 Node 和 Angular 部署到 Heroku 错误

git - ~/.gitconfig 中针对 Mac 的特定优化

git - 邪恶在 git 中 merge - 它们来自哪里?