Git diff:是否可以仅显示更改的行 [英] Git diff: is it possible to show ONLY changed lines
问题描述
对于:
$我试图只获取已更改的新版本行,并不是所有其他信息都是git diff显示的。 b
$ b
git diff HEAD --no-ext-diff --unified = 0 --exit-code -a --no-prefix
显示:
diff --git file1 file2
index d9db605..a884b50 100644
--- file1
+++ file2
@@ -16 +16 @@ bla bla bla
-old text
+ new text
我想看到的仅仅是:
新文字
是否有可能?
只有添加的行在所有情况下都没有意义。如果你替换了一些文本块,而你发现前面包含了一行,git必须匹配并猜测。 - 通常, git diff
的输出可以用作 patch
之后的输入,因此是有意义的。只有添加的行没有被精确定义,因为git在某些情况下不得不猜测。
如果您仍然需要它,您不能相信领先的 +
单独签字。也许过滤所有绿线比较好:
git diff --color = always | perl -wlne'print $ 1 if / ^ \\\ [32m \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ / pre>
仅针对已删除的行过滤所有红线:
git diff --color = always | perl -wlne'如果/^\e\[31m-(.*)\e\[m$/'
$ c $打印$ 1 c>
检查您可以使用的输出中的颜色代码:
git diff --color = always | ruby -wne'p $ _'
I'm trying to get only new version of lines which have changed and not all the other info which git diff shows.
For:
git diff HEAD --no-ext-diff --unified=0 --exit-code -a --no-prefix
It shows:
diff --git file1 file2
index d9db605..a884b50 100644
--- file1
+++ file2
@@ -16 +16 @@ bla bla bla
-old text
+new text
what I want to see is only:
new text
Is it possible?
解决方案 Only added lines does not make sense in all cases. If you replaced some block of text and you happend to include a single line which was there before, git has to match and guess. - Usually the output of git diff
could be used as input for patch
afterwards and is therefore meaningful. Only the added lines are not precisely defined as git has to guess in some cases.
If you nevertheless want it, you cannot trust a leading +
sign alone. Maybe filtering all the green line is better:
git diff --color=always|perl -wlne 'print $1 if /^\e\[32m\+\e\[m\e\[32m(.*)\e\[m$/'
for only deleted lines filter for all the red lines:
git diff --color=always|perl -wlne 'print $1 if /^\e\[31m-(.*)\e\[m$/'
to inspect the color codes in the output you could use:
git diff --color=always|ruby -wne 'p $_'
这篇关于Git diff:是否可以仅显示更改的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!