stage用法 - git查看远程提交记录
使'git日志'忽略某些路径的更改 (2)
我怎样才能让git log
只显示提交的文件,而不是我指定的文件?
使用git log
,我可以过滤提交给那些触及给定路径的提交。 我想要的是反转该过滤器,以便只列出触及非指定路径的提交。
我可以得到我想要的
git log --format="%n/%n%H" --name-only | ~/filter-log.pl | git log --stdin --no-walk
其中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";
}
}
除了我想要比这更优雅的东西。
请注意,我不问如何让git忽略这些文件。 这些文件应该被跟踪并提交。 只是这样,大多数时候,我不想看到他们。
相关问题: 如何取消`git log --grep = <pattern>`或如何显示不匹配模式的git日志除了提交消息而不是路径外,它是同一个问题。
关于2008年这个问题的论坛讨论: Re:从git-diff中排除文件这看起来很有希望,但是线程似乎已经枯竭了。
tl; dr: shopt -s extglob && git log !(unwanted/glob|another/unwanted/glob)
如果你使用Bash,你应该可以使用扩展的globbing功能来获取你需要的文件:
$ 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 <[email protected]>
Date: Wed Jun 5 10:58:45 2013 +0200
First commit
您可以将它与globstar
结合起来进行递归操作。
它现在实施(git 1.9 / 2.0,2014年第一季度),介绍pathspec magic :(exclude)
及其简短形式:!
在提交ef79b1f和提交1649612 ,由NguyễnTháiNgọcDuy( pclouds
) 提交 。
您现在可以记录除子文件夹内容以外的所有内容:
git log -- . ":(exclude)sub"
git log -- . ":!sub"
或者您可以排除该子文件夹中的特定元素
一个特定的文件:
git log -- . ":(exclude)sub/sub/file" git log -- . ":!sub/sub/file"
sub
任何给定文件:git log -- . ":(exclude)sub/*file" git log -- . ":!sub/*file" git log -- . ":(exclude,glob)sub/*/file"
您可以使排除大小写不敏感!
git log -- . ":(exclude,icase)SUB"
正如Kenny Evitt指出的那样
如果您在Bash shell中运行Git,请使用
':!sub'
或":\!sub"
来代替以避免bash: ... event not found
错误
注意:Git 2.13(Q2 2017)将添加一个同义词^
to !
请参阅承诺859b7f1 , 提交42ebeb9 (2017年2月8日)作者: Linus Torvalds( torvalds
) 。
(由Junio C gitster
合并- gitster
- 2017年2月27日提交015fba3 )
pathspec magic:添加'
^
'作为'!
'的别名 “'
!
'的选择 '对于负面路径规格的结果不仅与我们对修订所做的不匹配,而且因为需要引用而对shell扩展也是一个可怕的特性。
因此,添加' ^
'作为排除pathspec条目的替代别名。