这是在git log -p中忽略文件的后续内容,也与使'git log'忽略某些路径的更改有关.
我正在使用Git 1.9.2.我正在尝试使用pathspec魔术:(exclude)来指定某些补丁不应该在输出中显示git log -p.但是,我要排除的修补程序仍显示在输出中.
这是一个重现这种情况的最小工作示例:
$ cd ~/Desktop
$ mkdir test_exclude
$ cd test_exclude
$ git init
$ mkdir testdir
$ printf "my first cpp file\n" > testdir/test1.cpp
$ printf "my first xml file\n" > testdir/test2.xml
$ git add testdir/
$ git commit -m "added two test files"
Run Code Online (Sandbox Code Playgroud)
现在我想显示我的历史记录中的所有补丁,期望与文件testdir夹中的XML文件相对应的补丁.因此,按照VonC的回答,我跑了
$ git log --patch -- . ":(exclude)testdir/*.xml"
Run Code Online (Sandbox Code Playgroud)
但我的testdir/test2.xml文件的补丁仍显示在输出中:
commit 37767da1ad4ad5a5c902dfa0c9b95351e8a3b0d9
Author: xxxxxxxxxxxxxxxxxxxxxxxxx
Date: Mon Aug 18 12:23:56 2014 +0100
added two test files
diff --git a/testdir/test1.cpp b/testdir/test1.cpp
new file mode 100644
index 0000000..3a721aa
--- /dev/null
+++ b/testdir/test1.cpp
@@ -0,0 +1 @@
+my first cpp file
diff --git a/testdir/test2.xml b/testdir/test2.xml
new file mode 100644
index 0000000..8b7ce86
--- /dev/null
+++ b/testdir/test2.xml
@@ -0,0 +1 @@
+my first xml file
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我该怎么做才能告诉我不要git log -p显示与我testdir文件夹中所有XML文件相关的补丁?
没关系.问题似乎已在Git 1.9.5中修复(更具体地说,在提交中ed22b4173bd8d6dbce6236480bd30a63dd54834e).上面我的问题中的玩具示例在Git 2.2.1中按预期工作:
$ git --version
git version 2.2.1
$ mkdir test_exclude
$ cd test_exclude/
$ git init
Initialized empty Git repository in /Users/jubobs/Desktop/test_exclude/.git/
$ mkdir testdir
$ printf "my first cpp file\n" > testdir/test1.cpp
$ printf "my first xml file\n" > testdir/test2.xml
$ git add testdir/
$ git commit -m "added two test files"
[master (root-commit) 5429d04] added two test files
2 files changed, 2 insertions(+)
create mode 100644 testdir/test1.cpp
create mode 100644 testdir/test2.xml
$ git log --patch -- . ":(exclude)testdir/*.xml"
commit 5429d047f140f96c5d6167d083fc1a5eab05fb19
Author: xxxxxxxxxxxxxxxxxxxxxxxxx
Date: Fri Dec 26 23:40:18 2014 +0100
added two test files
diff --git a/testdir/test1.cpp b/testdir/test1.cpp
new file mode 100644
index 0000000..3a721aa
--- /dev/null
+++ b/testdir/test1.cpp
@@ -0,0 +1 @@
+my first cpp file
Run Code Online (Sandbox Code Playgroud)
如您所见,根据需要test2.xml,该git log命令的输出中没有提及.