使'git日志'忽略某些路径的更改 [英] Making 'git log' ignore changes for certain paths

查看:256
本文介绍了使'git日志'忽略某些路径的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎样才能让 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;
使用警告;

$ / =\\\
/ \\\
;
<>; (<>){
my($ commit,@files)= split / \ n /,$ _;

。 (grep {$ _&& $ _!〜m [^(/ $ | .etckeeper $ | lvm /(archive | backup)/)]} @files){


打印$ commit\\\
;
}
}

除了我想要比这更优雅的东西。 / p>

请注意,我不是要求如何让git忽略这些文件。这些文件应该被跟踪并提交。只是,大多数时候,我对看到它们并不感兴趣。



相关问题:如何反转`git log --grep =< pattern> `或者如何显示与模式不匹配的git日志除了提交消息而不是路径之外,这是同一个问题。



有关此主题的论坛讨论从2008年开始: Re:从git-diff中排除文件这看起来很有希望,但该线程似乎已经干涸。

解决方案

现在已经实施了(git 1.9 / 2.0,Q1 2014) strong> pathspec magic :(排除)及其简短形式:! in commit ef79b1f commit 1649612 ,by


你现在可以记录除子文件夹内容以外的所有内容:



git log - 。 :(排除)子
git log - 。 :!sub

或者您可以排除该子文件夹中的特定元素




  • 特定文件:
    $ b

      git log  - 。 :(排除)子/子/文件
    git log - 。 :!sub / sub / file


  • sub


    $ b

      git log  - 。 :(排除)sub / *文件
    git log - 。 :!sub / *文件
    git log - 。 :(exclude,glob)sub / * / file




您可以使排除不区分大小写!


$ b

  git log  - 。 :(exclude,icase)SUB

As Kenny Evitt指出


如果您在Bash shell中运行Git ,请使用':!sub':\!sub来避免 bash:...未找到事件错误






注意:Git 2.13(Q2 2017)会添加一个同义词 ^



请参阅 commit 859b7f1 commit 42ebeb9 (2017年2月8日)作者: Linus Torvalds( torvalds

(由 Junio C Hamano - gitster -


pathspec magic:add'<$ rel =noreferrer> commit 015fba3 ,2017年2月27日) c $ c $ ^ b


''对于否定pathspec结束不仅不匹配
我们对修订所做的操作,它也是shell
扩展的可怕字符,因为它需要引用。


因此,添加' ^ '作为替代别名不包括pathspec条目。


How can I make git log only show commits that changed files other than the ones I specify?

With git log, I can filter the commits I see to those that touch a given set of paths. What I want is to invert that filter so that only commits that touch paths other than the specified ones will be listed.

I can get what I want with

git log --format="%n/%n%H" --name-only | ~/filter-log.pl | git log --stdin --no-walk

where filter-log.pl is:

#!/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";
    }
}

except I want something somewhat more elegant than that.

Note that I am not asking how to make git ignore the files. These files should be tracked and committed. It's just that, most of the time, I'm not interested in seeing them.

Related question: How to invert `git log --grep=<pattern>` or How to show git logs that don't match a pattern It's the same question except for commit messages rather than paths.

Forum discussion on this subject from 2008: Re: Excluding files from git-diff This looked promising but the thread seems to have dried up.

解决方案

It is implemented now (git 1.9/2.0, Q1 2014) with the introduction pathspec magic :(exclude) and its short form :! in commit ef79b1f and commit 1649612, by Nguyễn Thái Ngọc Duy (pclouds).

You now can log everything except a sub-folder content:

git log -- . ":(exclude)sub"
git log -- . ":!sub"

Or you can exclude specific elements within that sub-folder

  • a specific file:

    git log -- . ":(exclude)sub/sub/file"
    git log -- . ":!sub/sub/file"
    

  • any given file within sub:

    git log -- . ":(exclude)sub/*file"
    git log -- . ":!sub/*file"
    git log -- . ":(exclude,glob)sub/*/file"
    

You can make that exclusion case insensitive!

git log -- . ":(exclude,icase)SUB"

As Kenny Evitt noted

If you're running Git in a Bash shell, use ':!sub' or ":\!sub" instead to avoid bash: ... event not found errors


Note: Git 2.13 (Q2 2017) will add a synonym ^to !

See commit 859b7f1, commit 42ebeb9 (08 Feb 2017) by Linus Torvalds (torvalds).
(Merged by Junio C Hamano -- gitster -- in commit 015fba3, 27 Feb 2017)

pathspec magic: add '^' as alias for '!'

The choice of '!' for a negative pathspec ends up not only not matching what we do for revisions, it's also a horrible character for shell expansion since it needs quoting.

So add '^' as an alternative alias for an excluding pathspec entry.

这篇关于使'git日志'忽略某些路径的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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