git - 如何排除带有 "git diff"的补丁 header ?

标签 git

例如在 git diff

的以下输出中
diff --git a/commands.txt b/commands.txt
index 79e881a..a9588e5 100644
--- a/commands.txt
+++ b/commands.txt
@@ -1,3 +1,7 @@
+this is an example
+abcxyz
+helllo
+wooo
 makeFilePermissionExecutable
 makeOwnedByMyself
 makeFilePermissionEverything

是否可以 stash 以下内容:

diff --git a/commands.txt b/commands.txt
index 79e881a..a9588e5 100644
--- a/commands.txt
+++ b/commands.txt

而是只显示文件名(在本例中为 commands.txt)?

最佳答案

git 差异 | tail -n +5 将产生您想要的输出。

我们将 git diff 的输出通过管道传输到 tail -n +5 以在第 5 行开始输出。参见 man 页面 尾-n:

   -n, --lines=[+]NUM
          output the last NUM lines, instead of the last  10;  or  use  -n
          +NUM to output starting with line NUM

如果您想要 merge --- a/commands.txt+++ b/commands.txt,您将不得不做一些额外的正则表达式工作> 到单行。

关于git - 如何排除带有 "git diff"的补丁 header ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47496283/

相关文章:

git - 如何在父级 merge 后处理主题分支的 merge

git - 如何从任何地方将*所有*新的/修改过的文件添加到git? (如 `git add -A` ,或 `git commit -a` 用于新文件)

git - 当我的分支和主人没有相关历史时如何做 pull 请求?

git - Gitlab CE 的高内存使用率

git - 如何断开项目与 github 存储库的连接并连接到另一个?

Git-Tf 移动大型 Tfs 项目的部分

git - 在 Git 中查找文件何时被删除

git - '--set-upstream' 是做什么的?

git - 子模块没有出现在 repo 中

git - 推送到位于 RDP 客户端上的 git 存储库