1

How do we exclude Notes added by 'git notes add' from git log?

When we run git log --all, there are millions of lines with Notes added by 'git notes add'. We need --all to see everything else. We just don't want the commits that add the notes. However, we do want to see the actual notes itself that was attached to commits.

There's probably a duplicate question somewhere out there but I've search for over 8 hours and still can't find one.

For example: git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset) %C(red)%N %C(reset)' --all displays the following (where Tested is the notes):

  • 1b15b8e - (3 hours ago) Notes added by 'git notes add' - maker2
  • 06b1158 - (2 hours ago) Fixed bug #37 - maker2 Tested

We actually want:

  • 06b1158 - (2 hours ago) Fixed bug #37 - maker2 Tested

We don't want:

  • 1b15b8e - (3 hours ago) Notes added by 'git notes add' - maker2

Using --no-notes actually produces the following, which is NOT the output we want:

  • 1b15b8e - (3 hours ago) Notes added by 'git notes add' - maker2 %N
  • 06b1158 - (2 hours ago) Fixed bug #37 - maker2 %N

Git version is 1.7.1

The current work around we have is to use | grep -v 'Notes added by' | less -r but the output now gets colored strangely with the graph lines are displayed in rainbow colors for some reason.

Fun Mun Pieng
  • 6,751
  • 3
  • 28
  • 30
  • See `--no-notes`, assuming it's in 1.7.1. If not, upgrade Git. (Or did you want *some* notes? There's no way to pick and choose which notes, other than choosing a specific notes ref.) – torek Oct 27 '21 at 09:54
  • @torek --no-notes just excludes the notes that we actually want to see, but still displays all the commits that say `Notes added by 'git notes add'`. We want to see the notes. We just don't want the commit. – Fun Mun Pieng Oct 27 '21 at 09:59
  • This looks like something you can filter out using `grep`... – Vincent Fourmond Oct 27 '21 at 10:26

2 Answers2

3
git log --exclude='refs/notes/*' --all ...

From the docs:

   --exclude=<glob-pattern>
       Do not include refs matching <glob-pattern>
       that the next --all, --branches, --tags,
       --remotes, or --glob would otherwise consider.
       Repetitions of this option accumulate
       exclusion patterns up to the next --all,
       --branches, --tags, --remotes, or --glob
       option (other options or arguments do not
       clear accumulated patterns).

       The patterns given should not begin with
       refs/heads, refs/tags, or refs/remotes when
       applied to --branches, --tags, or --remotes,
       respectively, and they must begin with refs/
       when applied to --glob or --all. If a trailing
       /* is intended, it must be given explicitly.
hraban
  • 1,819
  • 1
  • 17
  • 27
  • Unfortunately, the option is not available in 1.7.1 – Fun Mun Pieng Nov 16 '21 at 07:00
  • 1
    Even on 2.32.0, it still doesn't exclude `Notes added by 'git notes add'` – Fun Mun Pieng Nov 16 '21 at 07:07
  • @FunMunPieng it was added in 1.9.0: https://github.com/git/git/blob/master/Documentation/RelNotes/1.9.0.txt#L156 . Are you really sure it doesn't work? I use it myself, with notes, and it 100% has the documented effect. v2.33.1. Double check the order of your args? v1.9.0 was released in 2014, v1.7.1 was released in 2010. If there's any way you can upgrade, I'd try an upgrade :) – hraban Nov 16 '21 at 18:55
0

The solution seems to be to just grep out the unwanted lines and sed out the unwanted colors. Basically appending the git log with | grep -v 'Notes added by' | sed -e 's/^|/\x1b[m|/g' -e 's/^\*/\x1b[m\*/g' | less -R

The full command line:

git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset) %C(red)%N %C(reset)' --all | grep -v 'Notes added by' |
  sed -e 's/^|/\x1b[m|/g' -e 's/^\*/\x1b[m\*/g' | less -R

grep -v 'Notes added by' removes the lines containing the notes commit.

sed -e 's/^|/\x1b[m|/g' -e 's/^\*/\x1b[m\*/g' prefixes the first | or * in the line with the ANSI escape code to reset colors

less -R displays the out with colors and correct line width.

Fun Mun Pieng
  • 6,751
  • 3
  • 28
  • 30