git - 如何仅过滤以 git 上下文格式修改的行

标签 git git-difftool

我使用以下命令来确定两次提交之间修改的行数。 b26e.. 和 e1f5... 是提交哈希

git difftool -y -x "diff -c" b26ea5c511970d0211186c3b1e119224465ad365 e2f5104a2dd1afdc27803ead58b74cfd18ae50be

下面是文件的输出

*** /tmp/n90Z9a_Testing.txt 2016-12-02 11:47:59.027168926 +0530
--- /tmp/19ymab_Testing.txt 2016-12-02 11:47:59.027168926 +0530
***************
*** 1,3 ****
  initial commit
  added new line
! added for modification
--- 1,5 ----
  initial commit
  added new line
! added for modification, this is modified.This is modified again
! after modifiying for the second time, this line is added
! This line added for complete deletion and then replace with another

由此,我只需要过滤掉第一次提交时修改的行,简单来说,我只需要从上面的输出中过滤这部分

*** /tmp/n90Z9a_Testing.txt 2016-12-02 11:47:59.027168926 +0530
--- /tmp/19ymab_Testing.txt 2016-12-02 11:47:59.027168926 +0530
***************
*** 1,3 ****
  initial commit
  added new line
! added for modification

如何过滤掉它,先谢谢了

最佳答案

如果这只是selecting lines between two markers ,您可以使用sed:

sed -n -e "/^\*\*\*/,/^---/{ /^---/d; p; }"

即:

git difftool -y -x "diff -c" <shaX> <shaY> | sed -n -e "/^\*\*\*/,/^---/{ /^---/d; p; }"

这将打印“***”(包含)和“---”(排除)之间的所有内容

关于git - 如何仅过滤以 git 上下文格式修改的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40926220/

相关文章:

git - 如何让 git log 显示相对于当前目录的文件路径?

git difftool -d 查看两个历史提交之间的差异

git - Jenkins Git 参数插件无法获取标签

node.js - 无法运行 nodejs 项目 - npm ERR!代码 EBADPLATFORM

difftool 不会显示 Git diff -cc 模式

git - 将 meld.exe 作为外部 git difftool 启动时出现 Meld 错误 “Cannot import: GTK+; DLL load failed"

Git difftool 在 Cygwin/MinGW 中慢得离谱

gitolite:允许任何 repo RW+CD 的 RW 用户到他们的个人分支,不允许其他人

git - 在 Git 中查找更改最多的文件

Git,恢复或重置到某个提交