问题描述
我被分配了一个任务,从git存储库中删除不必要的文件。这导致删除许多文件并编辑其他文件。当我发出git show
或git log -p
时,我的屏幕上充斥着已删除文件的内容,而我很难找到有意义的部分,这些部分是我在其他文件中所做的修改。
插图:
--- a/path/to/a/file
+++ /dev/null
@@ -1,41 +0,0 @@
-Lots of content I don't want to see.
-Lots of content I don't want to see.
-Lots of content I don't want to see.
-Lots of content I don't want to see.
-Lots of content I don't want to see.
-...
有什么方法可以禁止显示已删除文件的内容?
解决方法
一个解决方案是
git show 3764981273649817263498712 \
| sed '/^\+\+\+ \/dev\/null/,/^diff/d' \
| colordiff \
| less -R
注意
如果git show
的输出不是交互式的(通过管道传递到其他命令),则不会着色,也不会调用寻呼机(如less
)。依次调用colordiff
和less -R
可以解决此问题。
骗局
输出不精确,但对人类来说足够好。