'Making 'git log' ignore changes for certain paths
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.
Solution 1:[1]
tl;dr: shopt -s extglob && git log !(unwanted/glob|another/unwanted/glob)
If you're using Bash you should be able to use the extended globbing feature to get only the files you need:
$ 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
You can combine this with globstar for recursive action.
Solution 2:[2]
You can temporarily ignore the changes in a file with:
git update-index --skip-worktree path/to/file
Going forward, all changes to those files will be ignored by git status, git commit -a, etc. When you're ready to commit those files, just reverse it:
git update-index --no-skip-worktree path/to/file
and commit as normal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | l0b0 |
| Solution 2 | rubysolo |
