忽略git log -p中的文件 [英] Ignore files in git log -p

查看:184
本文介绍了忽略git log -p中的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这些文件位于名为 mtest 的单个目录中;但是,该文件夹还包含我想要显示的测试套件代码。我想排除的测试文件的扩展名为 mscx xml ,所以我希望过滤器工作在在那。



我曾看过使'git log'忽略某些路径的更改,但这看起来像是排除了修改文件的提交,而不是简单排除文件。



有没有办法做到这一点?



我试过Jubobs的答案,它似乎工作,但令人惊讶的是,即使在过滤器上也有2个文件出现。 / b>

我已经在这个小版本库中转载了这个文件:

  mkdir test 
cd test
git init
echo'readme'> README
git add。
git commit -m初始提交

mkdir test2
cd test2
echo't1'> test1.cpp
echo't2'> test2.xml
git add。
git commit -mc2

echo't3'> test3.cpp
echo't4'> test4.xml
git add。
git commit -mc3

我注意到文件在目录被建造。
我已经尝试了以下命令:

  git log --patch  - 。 :(不包括)** / *。xml

导致

  git log --patch  - 。 :(exclude)*。xml

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

解决方案

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

  git log --patch  - 。 :(除外)*。xml

可以在玩具示例中实现你想要的功能:尽可能如下所示,根据需要将所有 *。xml 文件滤除。


$ b

  $ mkdir test 
$ cd test
$ git init
在/Users/jubobs/Desktop/test/.git/ $ b $中初始化的空Git存储库b
$ echo'readme'> README
$ git add。
$ git commit -m初始提交
[master(root-commit)ad6cc73]初始提交
1个文件已更改,1个插入(+)
创建模式100644自述文件

$ mkdir test2
$ cd test2
$ echo't1'> test1.cpp
$ echo't2'> test2.xml
$ git add。
$ git commit -mc2
[master 8d733a2] c2
2个文件已更改,2个插入(+)
创建模式100644 test2 / test1.cpp
创建模式100644 test2 / test2.xml

$ echo't3'> test3.cpp
$ echo't4'> test4.xml
$ git add。
$ git commit -mc3
[master 3e8a3f6] c3
2个文件已更改,2个插入(+)
创建模式100644 test2 / test3.cpp
创建模式100644 test2 / test4.xml

$ git log --patch - 。 :(exclude)*。xml
commit 3e8a3f6c627576e8f7d1863b92d4f631ae309417
作者:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
日期:Sat Dec 27 00:19:56 2014 +0100

c3

diff --git a / test2 / test3.cpp b / test2 / test3.cpp
新文件模式100644
索引0000000..6d6ea65
--- / dev / null
+++ b / test2 / test3.cpp
@@ -0,0 +1 @@
+ t3

commit 8d733a27a0e2c9f4c71e7b64742107255035d6cd
作者:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
日期:Sat Dec 27 00:19:33 2014 +0100

c2

diff --git a / test2 / test1.cpp b / test2 / test1.cpp
新文件模式100644
索引0000000..795ea43
--- / dev / null
+++ b / test2 / test1.cpp
@@ -0,0 +1 @@
+ t1


I'm trying to summarize my work on a project. The problem is that I do not want to include test files in the output of git log --patch.

The files are in a single directory called mtest; however, that folder also contains test suite code that I do want to show. Test files, which I want to exclude, have extension mscx or xml, so I would want the filter to work based on that.

I have looked at Making 'git log' ignore changes for certain paths but this looks like it excludes commits that modified a file instead of simply excluding the file.

Is there a way to do this?

I have tried Jubobs answer, and it seemed worked, but surprisingly 2 files came up even with the filter on.

I have reproduced this with this small repository:

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"

I noticed that files are not filtered when a directory is created. I have tried the following commands:

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

which resulted in both xml files to be included.

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

This surprisingly filters out the test4.xml but not test2.xml.

解决方案

I don't know which version of Git you are/were using, but the problem you report appears to have been fixed in Git 1.9.5 (for more details about the bugfix, see this). The following command

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

does what you want in your toy example: as you can see below, all *.xml files get filtered out, as desired.

$ 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

这篇关于忽略git log -p中的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆