git log
除了我指定的文件外,我怎么才能只显示改变文件的提交?
有了git log
,我可以将我看到的提交过滤给那些触及给定路径的人.我想要的是反转该过滤器,以便只列出除指定的触摸路径以外的触摸路径.
我可以得到我想要的东西
git log --format="%n/%n%H" --name-only | ~/filter-log.pl | git log --stdin --no-walk
Run Code Online (Sandbox Code Playgroud)
在哪里filter-log.pl
:
#!/usr/bin/perl
use strict;
use warnings;
$/ = "\n/\n";
<>;
while (<>) {
my ($commit, @files) = split /\n/, $_;
if (grep { $_ && $_ !~ m[^(/$|.etckeeper$|lvm/(archive|backup)/)] } @files) {
print "$commit\n";
}
}
Run Code Online (Sandbox Code Playgroud)
除了我想要比这更优雅的东西.
请注意,我不是在问如何让git忽略这些文件.应跟踪和提交这些文件.就是这样,大多数时候,我对看到它们并不感兴趣.
相关问题:如何反转`git log --grep = <pattern>`或如何显示与模式不匹配的git日志除了提交消息而不是路径之外,它是同一个问题.
关于这个主题的论坛讨论从2008年开始:Re:从git-diff中排除文件这看起来很有希望,但线程似乎已经枯竭了.
Von*_*onC 191
它现在已经实现了(git 1.9/2.0,2014年第一季度),引用pathspec magic :(exclude)
及其缩写形式:!
在提交ef79b1f和提交1649612,由
NguyễnTháiNgọcDuy(pclouds
),文档可以在这里找到.
您现在可以记录除子文件夹内容之外的所有内容:
git log -- . ":(exclude)sub"
git log -- . ":!sub"
Run Code Online (Sandbox Code Playgroud)
或者,您可以排除该子文件夹中的特定元素
特定文件:
git log -- . ":(exclude)sub/sub/file"
git log -- . ":!sub/sub/file"
Run Code Online (Sandbox Code Playgroud)任何给定的文件sub
:
git log -- . ":(exclude)sub/*file"
git log -- . ":!sub/*file"
git log -- . ":(exclude,glob)sub/*/file"
Run Code Online (Sandbox Code Playgroud)您可以使该排除案例不敏感!
git log -- . ":(exclude,icase)SUB"
Run Code Online (Sandbox Code Playgroud)
如果您在Bash shell中运行Git,请使用
':!sub'
或":\!sub"
改为避免bash: ... event not found
错误
注:Git的2.13(Q2 2017)将同义词添加^
到!
请参阅Linus Torvalds()提交859b7f1,提交42ebeb9(2017年2月8日).(由Junio C Hamano合并- -在提交015fba3,2017年2月27日)torvalds
gitster
pathspec法宝:添加"
^
"作为别名"!
"选择'
!
'作为负路径规范最终不仅不匹配我们为修订做的事情,它也是shell扩展的可怕特征,因为它需要引用.
因此,添加' ^
'作为排除pathspec条目的替代别名.
tl; dr: shopt -s extglob && git log !(unwanted/glob|another/unwanted/glob)
如果您使用的是Bash,则应该能够使用扩展的globlobing功能来仅获取所需的文件:
$ cd -- "$(mktemp --directory)"
$ git init
Initialized empty Git repository in /tmp/tmp.cJm8k38G9y/.git/
$ mkdir aye bee
$ echo foo > aye/foo
$ git add aye/foo
$ git commit -m "First commit"
[master (root-commit) 46a028c] First commit
0 files changed
create mode 100644 aye/foo
$ echo foo > bee/foo
$ git add bee/foo
$ git commit -m "Second commit"
[master 30b3af2] Second commit
1 file changed, 1 insertion(+)
create mode 100644 bee/foo
$ shopt -s extglob
$ git log !(bee)
commit ec660acdb38ee288a9e771a2685fe3389bed01dd
Author: My Name <jdoe@example.org>
Date: Wed Jun 5 10:58:45 2013 +0200
First commit
Run Code Online (Sandbox Code Playgroud)
您可以将其与globstar
递归操作结合使用。
归档时间: |
|
查看次数: |
21381 次 |
最近记录: |