How to invert `git log --grep=` or How to show git logs that don't match a pattern

前端 未结 8 884
旧巷少年郎
旧巷少年郎 2020-12-02 22:34

I want to use git log to show all commits that do not match a given pattern. I know I can use the following to show all commits that do match a pattern:

8条回答
  •  独厮守ぢ
    2020-12-02 23:22

    As mentioned by VonC the best option is if you can update to Git 2.4.0 (which is currently on RC2). But even if you can't do that there is no reason for elaborate scripts. A (gnu) awk one-liner should do it. git log has the useful -z option to separate commits by a NUL-character which makes it easy to parse them:

    git log -z --pretty --stat | awk 'BEGIN{ RS="\0"; FS="\n\n" } !match($2, //)'
    

    If you don't have gnu awk, you probably should at least install that. Or port this script to your specific awk version, which I leave as an exercise for the reader ;-).

提交回复
热议问题