使'git日志'忽略某些path的变化
 我怎样才能使git log只显示更改的文件,而不是我指定的提交? 
 使用git log ,我可以过滤提交给那些碰到给定path的提交。 我想要的是反转该filter,以便只提交触摸path以外的指定的将被列出。 
我可以得到我想要的
 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日志除了提交消息而不是path之外,它是同样的问题。
从2008年论坛上讨论这个问题: Re:从git-diff中排除文件这看起来很有希望,但是线程似乎已经枯竭了。
 现在执行(git 1.9 / 2.0,2014年第1季度),介绍pathspec magic :(exclude)及其简短forms:! 在NguyễnTháiNgọcDuy( pclouds ) 提交ef79b1f和提交1649612 。 
您现在可以logging除子文件夹内容以外的所有内容:
 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 ! 
 见Linus Torvalds( torvalds ) 提交的859b7f1 , 提交42ebeb9 (2017年2月8日) 。 
  (由Junio C gitster合并- gitster – 2017年2月27日提交015fba3 ) 
pathspec magic:添加'
^'作为'!'的别名 “'
!'的select “对于一个负面的path规格结果不仅不符合我们所做的修改,这也是一个可怕的angular色扩展壳,因为它需要引用。
 因此,为不包含的pathspec条目添加“ ^ ”作为替代别名。 
  tl; dr: shopt -s extglob && git log !(unwanted/glob|another/unwanted/glob) 
如果您使用的是Bash,您应该可以使用扩展匹配function来获取所需的文件:
 $ 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 
 您可以将其与globstar结合起来进行recursion操作。 
您可以暂时忽略文件中的更改:
 git update-index --skip-worktree path/to/file 
 outlook未来,对这些文件所做的所有更改都将被git status , git commit -a等忽略。当您准备好提交这些文件时,只需将其反转: 
 git update-index --no-skip-worktree path/to/file 
并照常进行。