Git diff只显示已修改的行 [英] Git diff to show only lines that have been modified
问题描述
+这行添加了
已被删除的行:
- 此行被删除
但它也显示了许多未修改的行:
这一行没有修改
这行也没有修改
这导致实际的git diff看起来像这样:
+这行添加
这行不修改
- 删除这行
这行不修改
我可以让git只显示已修改的行并忽略所有未修改的其他代码吗?我已经写了一个方法,它将删除所有在它们前面没有+或 - 符号的行,但我确定必须有一个更简单的方法来执行此操作。
在我的git diff中,我只对看到已被修改的行感兴趣。
在此先感谢。
解决方案你想要的是一个包含0行上下文的diff。您可以通过以下方式生成:
git diff --unified = 0
或
git diff -U0
您也可以将其设置为该存储库的配置选项:
git config diff.context 0
全局,任何存储库:
git config --global diff.context 0
When I do a git diff, it shows lines that have been added:
+ this line is added
lines that have been removed:
- this line is removed
but it also shows many lines which are not modified:
this line is not modified this line is also not modified
This results in the actual git diff looking something like this:
+ this line is added this line is not modified - this line is removed this line is not modified
Can I ask git to show only lines that have been modified and ignore all other code which has not been modified? I have written a method which will remove all the lines which don't have a "+" or "-" sign in front of them, but I am sure there must be a simpler way to do this.
In my git diff, I am only interested in seeing the lines that have been modified.
Thanks in advance.
解决方案What you want is a diff with 0 lines of context. You can generate this with:
git diff --unified=0
or
git diff -U0
You can also set this as a config option for that repository:
git config diff.context 0
To have it set globally, for any repository:
git config --global diff.context 0
这篇关于Git diff只显示已修改的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!