8

There's a project we're working on where the majority of commits are added in by a front-end developer. He's editing mainly HTML, CSS, JavaScript files that are not related to the back-end work that I'm helping with. It would be great if I could show the git log minus commits added by the front-end developer, so I could get a view of commits just related to the backend.

Is there an option I can pass to git log that would allow me to exclude all commits by an author? I just want to exclude this one developer's commits, I still care about viewing commits from other developers as well.

Elliot Larson
  • 9,039
  • 4
  • 33
  • 55

4 Answers4

7

You need a Regular expression to match a line that doesn't contain a word? Negative lookahead will do just that, but you have to ask git to use --perl-regexp.

git log --author='^(?!krlmlr).*$' --perl-regexp

According to git help log,

--perl-regexp ... requires libpcre to be compiled in.

Apparently, not all gits out there have this; for the one shipped with Ubuntu 13.04, this works out of the box.

Community
  • 1
  • 1
krlmlr
  • 22,030
  • 13
  • 107
  • 191
  • So, this looks pretty elegant and is probably the correct answer. Unfortunately, my version of git wasn't compiled with pcre, so running the command gives me a related error message. I don't have time right now to do the recompile, but I'll accept the answer. I think the perl-regexp path is probably the right direction to go in. Thanks. – Elliot Larson Jul 25 '13 at 21:02
  • @ElliotLarson: I'm on Ubuntu 13.04, works out of the box for me. – krlmlr Jul 26 '13 at 04:25
  • Hm, I installed git with Homebrew on my Mac. I'll have to research why the Homebrew version doesn't come with pcre added in by default when it's standard on Ubuntu. Sometimes, these things "fail" silently at compile time with Homebrew if there's funkiness on the system, meaning it's possible some Perl libraries weren't found in the expected places and the resulting compile flag was left off. – Elliot Larson Jul 26 '13 at 07:47
  • 1
    Awesome. In case you have more than one author you'd like to exclude, you can use `--author='^(?!(author1|author2)).*$'` – yhager Oct 23 '14 at 23:53
3
git rev-list --format='%aN' --all \
| sed 'N;/\nauthorname$/d;s/commit \(.*\)/\n.*/\1/' \
| git log --stdin

and of course substitute whatever heads you want for --all above.

Edit: list/select/process pipelines like this are bread and butter, it's just how git (like a lot of unix tools) was built.

jthill
  • 42,819
  • 4
  • 65
  • 113
  • I couldn't get this to work for some reason, although I'm a total noob with sed. It could just be that this is really close to what I'm looking for, but I'm just not quite sed savvy enough to wrangle the command. – Elliot Larson Jul 25 '13 at 20:58
0

I think this article explains it clearly. (Though it was mentioned under @trojanfoe link). Mainly, it says:

However it’s tricky to exclude commits by a particular author or set of authors using regular expressions as noted here. Instead, turn to bash and piping you can exclude commits authored by Adam by:

git log --format='%H %an' |  # get a list of all commit hashes followed by the author name
grep -v Adam |             # match the name but return the lines that *don't* contain the name
cut -d ' ' -f1 |           # from this extract just the first part of the line which is commit ref
xargs -n1 git log -1       # call git log from that commit stopped after 1 commit

A limitation of this is that some log options that you would want are not available such as --graph due to the mechanics of calling git log multiple times.

Antonio
  • 1,227
  • 12
  • 21
  • 1
    What exactly does "this article" explain? Please summarize -- only a link is not an answer. – krlmlr Jul 25 '13 at 19:18
  • I saw this article in my initial search. This doesn't really solve my problem, unless I want to take the approach of naming all authors except for one, which isn't a great solution. The resulting command would be ugly and error prone. I could see myself creating an alias for it, and then every time we add someone new to the team, I have to update my alias, but not before running my alias and being briefly confused about why the commits for "Dave" (a new developer) aren't showing up. I'd rather just exclude one author. – Elliot Larson Jul 25 '13 at 20:55
  • Merely posting a link without any relevant quotes is ***not*** a good answer. What if the link breaks in the future? Then the answer becomes completely useless. If you quote the relevant information from the link in your answer, then we'll still have the information available on Stack Overflow, even if the link breaks. –  Jul 26 '13 at 05:01
  • Sorry, guys - you concerns look reasonable, so I adjusted the answer. Though, not very helpful, because the author of the question already mentioned that he saw this approach. – Antonio Jul 26 '13 at 05:09
0

It's more flexible to use

git log -i --author="^((?!abc).)*$" --perl-regexp

instead of

git log -i --author="^(?!abc).*$" --perl-regexp

The difference is that the latter one only excludes authors starting with abc, i.e., author abcddd, but not ddabcd or dddabc etc, while the former one will exclude all of those examples :) See Finding Lines Containing or Not Containing Certain Words in this post

I've tested these two with Git on Windows 10.

cateyes
  • 2,994
  • 1
  • 20
  • 26