【发布时间】:2020-09-10 06:56:01
【问题描述】:
是否可以格式化 git diff 的输出,以便我只得到实际的文本差异?
例如,这是默认的 git diff 输出:
diff --git a/diff_test.txt b/diff_test.txt
index 6b0c6cf..b37e70a 100644
--- a/diff_test.txt
+++ b/diff_test.txt
@@ -1 +1 @@
-this is a git diff test example
+this is a diff example
相反,我想得到:
diff --git a/diff_test.txt b/diff_test.txt
-this is a git diff test example
+this is a diff example
是否可以使用 git diff 或其他 git 命令不使用 使用 shell、python 等其他脚本?
【问题讨论】:
-
我做到了,但找不到摆脱标题的方法。如果您在那里看到答案,请将其作为我的问题的答案发布。
-
如果你在使用 bash,你可以通过管道跳过前 4 个标题行到 sed。例如。 git diff ... | sed 1,4d
-
感谢@StPiere,但我试图弄清楚没有 bash 是可能的。
-
我认为没有 git diff 选项可以做到这一点。你必须使用管道。
标签: git