我使用以下命令来确定两次提交之间修改的行数。 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/