我正在尝试总结我在一个项目上的工作。问题是我不想在输出中包含测试文件git log --patch
.
这些文件位于一个名为mtest
;但是,该文件夹还包含我确实想展示的测试套件代码。我想排除的测试文件具有扩展名mscx
or xml
,所以我希望过滤器能够基于此工作。
我看过使“git log”忽略某些路径的更改 https://stackoverflow.com/questions/5685007/making-git-log-ignore-changes-for-certain-paths但这看起来像是排除了修改文件的提交,而不是简单地排除该文件。
有没有办法做到这一点?
我已经尝试过 Jubos 的回答,它似乎有效,但令人惊讶的是,即使打开了过滤器,也出现了 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"
这导致both要包含的 xml 文件。
git log --patch -- . ":(exclude)*.xml"
这令人惊讶地过滤掉了test4.xml
但不是test2.xml
.
我不知道您正在使用哪个版本的 Git,但您报告的问题似乎已在 Git 1.9.5 中修复(有关错误修复的更多详细信息,请参阅this https://stackoverflow.com/a/27662758/2541573)。以下命令
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)