【问题标题】:How do we exclude `Notes added by 'git notes add'` from `git log`?我们如何从`git log`中排除`git notes add'添加的注释?
【发布时间】:2021-12-12 14:32:23
【问题描述】:

我们如何从git log 中排除Notes added by 'git notes add'

当我们运行git log --all 时,有数百万行带有Notes added by 'git notes add'。我们需要 --all 来查看其他所有内容。我们只是不想要添加注释的提交。但是,我们确实希望看到附加到提交的实际注释本身。

那里可能有一个重复的问题,但我已经搜索了超过 8 个小时,但仍然找不到。

例如: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 显示以下内容(其中Tested 是注释):

  • 1b15b8e -(3 小时前)由“git notes add”添加的注释 - maker2
  • 06b1158 -(2 小时前)修复了错误 #37 - maker2 Tested

我们实际上想要:

  • 06b1158 -(2 小时前)修复了错误 #37 - maker2 Tested

我们不想要:

  • 1b15b8e -(3 小时前)由“git notes add”添加的注释 - maker2

使用 --no-notes 实际上会产生以下结果,这不是我们想要的输出:

  • 1b15b8e -(3 小时前)由“git notes add”添加的注释 - maker2 %N
  • 06b1158 -(2 小时前)修复了错误 #37 - maker2 %N

Git 版本为 1.7.1

我们目前的解决方法是使用 | grep -v 'Notes added by' | less -r,但现在输出颜色变得奇怪,图形线由于某种原因以彩虹色显示。

【问题讨论】:

  • 参见--no-notes,假设它在 1.7.1 中。如果没有,请升级 Git。 (或者您想要 一些 笔记吗?除了选择特定的笔记参考之外,没有办法挑选哪些笔记。)
  • @torek --no-notes 只是排除了我们真正想看到的注释,但仍然显示所有提到Notes added by 'git notes add' 的提交。我们想看笔记。我们只是不想提交。
  • 这看起来像是你可以使用grep过滤掉的东西...

标签: git git-log git-notes


【解决方案1】:
git log --exclude='refs/notes/*' --all ...

来自文档:

   --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.

【讨论】:

  • 很遗憾,该选项在 1.7.1 中不可用
  • 即使在 2.32.0 上,它仍然不排除 Notes added by 'git notes add'
  • @FunMunPieng 它是在 1.9.0 中添加的:github.com/git/git/blob/master/Documentation/RelNotes/…。你真的确定它不起作用吗?我自己使用它,并带有注释,它 100% 具有记录的效果。 v2.33.1。仔细检查你的参数的顺序? v1.9.0 于 2014 年发布,v1.7.1 于 2010 年发布。如果有什么方法可以升级,我会尝试升级 :)
【解决方案2】:

解决方案似乎只是grep 去掉不需要的线条,sed 去掉不需要的颜色。基本上是在git log 后面加上 | grep -v 'Notes added by' | sed -e 's/^|/\x1b[m|/g' -e 's/^\*/\x1b[m\*/g' | less -R

完整的命令行:

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' 删除包含注释提交的行。

sed -e 's/^|/\x1b[m|/g' -e 's/^\*/\x1b[m\*/g' 在行中的第一个 |* 前加上 ANSI 转义码以重置颜色

less -R 以颜色和正确的线宽显示输出。

【讨论】:

  • 这将在奇怪的位置显示一些图形线......所以,这不是一个完美的解决方案。
猜你喜欢
  • 1970-01-01
  • 2016-06-16
  • 1970-01-01
  • 1970-01-01
  • 2023-04-02
  • 1970-01-01
  • 2016-02-18
  • 2018-10-08
  • 1970-01-01
相关资源
最近更新 更多