忽略git log -p中的文件

时间:2014-08-16 11:43:43

标签: git git-log

我正在尝试总结我在项目上的工作。问题是我不想在git log --patch的输出中包含测试文件。

文件位于名为mtest的单个目录中;但是,该文件夹还包含我想要显示的测试套件代码。我想要排除的测试文件具有扩展名mscxxml,因此我希望过滤器能够在此基础上运行。

我查看过Making 'git log' ignore changes for certain paths,但这似乎排除了修改文件而不是简单地排除文件的提交。

有办法做到这一点吗?

我已经尝试了Jubobs的回答,看起来很有效,但令人惊讶的是,即使使用了过滤器,也会出现2个文件。

我在这个小型存储库中重现了这个:

mkdir test
cd test
git init
echo 'readme' > README
git add .
git commit -m "Initial commit"

mkdir test2
cd test2
echo 't1' > test1.cpp
echo 't2' > test2.xml
git add .
git commit -m "c2"

echo 't3' > test3.cpp
echo 't4' > test4.xml
git add .
git commit -m "c3"

我注意到创建目录时不会过滤文件。 我尝试了以下命令:

git log --patch -- . ":(exclude)**/*.xml"

导致两个 xml文件都包含在内。

git log --patch -- . ":(exclude)*.xml"

这令人惊讶地过滤了test4.xml但不过滤test2.xml

1 个答案:

答案 0 :(得分:6)

我不知道您使用的是哪个版本的Git,但您报告的问题似乎已在Git 1.9.5中得到修复(有关错误修正的详细信息,请参阅this)。以下命令

git log --patch -- . ":(exclude)*.xml"

在您的玩具示例中执行您想要的操作:如下所示,所有*.xml文件都会根据需要被过滤掉。

$ mkdir test
$ cd test
$ git init
Initialized empty Git repository in /Users/jubobs/Desktop/test/.git/

$ echo 'readme' > README
$ git add .
$ git commit -m "initial commit"
[master (root-commit) ad6cc73] initial commit
 1 file changed, 1 insertion(+)
 create mode 100644 README

$ mkdir test2
$ cd test2
$ echo 't1' > test1.cpp
$ echo 't2' > test2.xml
$ git add .
$ git commit -m "c2"
[master 8d733a2] c2
 2 files changed, 2 insertions(+)
 create mode 100644 test2/test1.cpp
 create mode 100644 test2/test2.xml

$ echo 't3' > test3.cpp
$ echo 't4' > test4.xml
$ git add .
$ git commit -m "c3"
[master 3e8a3f6] c3
 2 files changed, 2 insertions(+)
 create mode 100644 test2/test3.cpp
 create mode 100644 test2/test4.xml

$ git log --patch -- . ":(exclude)*.xml"
commit 3e8a3f6c627576e8f7d1863b92d4f631ae309417
Author: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Date:   Sat Dec 27 00:19:56 2014 +0100

    c3

diff --git a/test2/test3.cpp b/test2/test3.cpp
new file mode 100644
index 0000000..6d6ea65
--- /dev/null
+++ b/test2/test3.cpp
@@ -0,0 +1 @@
+t3

commit 8d733a27a0e2c9f4c71e7b64742107255035d6cd
Author: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Date:   Sat Dec 27 00:19:33 2014 +0100

    c2

diff --git a/test2/test1.cpp b/test2/test1.cpp
new file mode 100644
index 0000000..795ea43
--- /dev/null
+++ b/test2/test1.cpp
@@ -0,0 +1 @@
+t1