git - 如何从 `git log` 中排除一些标签?

标签 git

我有一个存储库,该存储库具有创建大量标签的自动化过程。示例:

* 5391e27 - (HEAD -> master, origin/master) Add a webhook to notify Phabricator of builds (2 hours ago) <Phil Frost>
* c380a48 - Retry downloading Selenium 3 times (2 hours ago) <Phil Frost>
| * 542731c - (tag: phabricator/diff/962) Retry downloading Selenium 3 times (6 hours ago) <Phil Frost>
|/
* 59509a3 - (tag: phabricator/base/962) Notify only on "master" branch (7 hours ago) <Phil Frost>
* 1504aa6 - Fix a few errors and omissions in README (7 hours ago) <Phil Frost>
| * a52940d - (tag: phabricator/diff/959) Notify only on "master" branch (3 days ago) <Phil Frost>
|/
| * 25838f0 - (tag: phabricator/diff/958) Notify only on "master" branch (3 days ago) <Phil Frost>
|/
* d7b3f72 - (tag: phabricator/base/959, tag: phabricator/base/958) Execute arbitrary commands in the test container (3 days ago) <Phil Frost>

通常,我不关心所有这些 phabricator/*/* 标签,所以我想查看所有 refs 的日志,except 那些。换句话说,我想看到这个:

* 5391e27 - (HEAD -> master, origin/master) Add a webhook to notify Phabricator of builds (2 hours ago) <Phil Frost>
* c380a48 - Retry downloading Selenium 3 times (2 hours ago) <Phil Frost>
* 59509a3 - Notify only on "master" branch (7 hours ago) <Phil Frost>
* 1504aa6 - Fix a few errors and omissions in README (7 hours ago) <Phil Frost>
* d7b3f72 - Execute arbitrary commands in the test container (3 days ago) <Phil Frost>

我认为这样做可以:

git log --exclude='refs/tags/phabricator/*/*' --all

不幸的是,无论我怎么尝试,--exclude 似乎都没有效果。我如何才能看到 git 日志中的所有引用,除了一些匹配模式的标签?

最佳答案

作为替代方案,使用 Git 2.16(2018 年第一季度),标记名“git log --decorate”用于注释提交可以 现在使用两个附加选项限制为可用引用的子集,--decorate-refs[-exclude]=<pattern> .

参见 commit 65516f5 (2017 年 11 月 21 日)Rafael Ascensão (``) .
帮助:Kevin Daudt ( Ikke ) , 和 Junio C Hamano ( gitster ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 6c3daa2 ,2017 年 12 月 13 日)

log: add option to choose which refs to decorate

When log --decorate is used, git will decorate commits with all available refs. While in most cases this may give the desired effect, under some conditions it can lead to excessively verbose output.

Introduce two command line options,

  • --decorate-refs=<pattern> and
  • --decorate-refs-exclude=<pattern>
    to allow the user to select which refs are used in decoration.

When "--decorate-refs=<pattern>" is given, only the refs that match the pattern are used in decoration. The refs that match the pattern when "--decorate-refs-exclude=<pattern>" is given, are never used in decoration.

在你的情况下:

git log -n6 --decorate=short --pretty="tformat:%f%d" \
        --decorate-refs-exclude="tags/phabricator/*"

在 Git 2.27(2020 年第 2 季度)中,“--decorate-refs”和“--decorate-refs-exclude”选项“git log”获取了一个伴随配置变量 log.excludeDecoration。在家庭中处于最低优先级。

参见 commit a6be5e6 , commit c9f7a79 (2020 年 4 月 16 日)Derrick Stolee ( derrickstolee ) .
(由 Junio C Hamano -- gitster -- merge 于 commit d3fc8dc ,2020 年 4 月 28 日)

log: add log.excludeDecoration config option

Helped-by: Junio C Hamano
Signed-off-by: Derrick Stolee

In 'git log', the --decorate-refs-exclude option appends a pattern to a string_list.
This list is used to prevent showing some refs in the decoration output, or even by --simplify-by-decoration.

Users may want to use their refs space to store utility refs that should not appear in the decoration output. For example, Scalar runs a background fetch but places the "new" refs inside the refs/scalar/hidden/<remote>/* refspace instead of refs/<remote>/* to avoid updating remote refs when the user is not looking.
However, these "hidden" refs appear during regular 'git log' queries.

A similar idea to use "hidden" refs is under consideration for core Git.

Add the 'log.excludeDecoration' config option so users can exclude some refs from decorations by default instead of needing to use --decorate-refs-exclude manually.
The config value is multi-valued much like the command-line option.
The documentation is careful to point out that the config value can be overridden by the --decorate-refs option, even though --decorate-refs-exclude would always "win" over --decorate-refs.

Since the 'log.excludeDecoration' takes lower precedence to --decorate-refs, and --decorate-refs-exclude takes higher precedence, the struct decoration_filter needed another field. This led also to new logic in load_ref_decorations() and ref_filter_match().

关于git - 如何从 `git log` 中排除一些标签?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36269366/

相关文章:

git - 如何让 git 工作以通过 tor 将提交推送到 GitHub?

从 git hub 下载后,laravel 项目大小变得非常大

git - 克隆 repo 的完整路径

由于丢失或损坏的本地对象 git-lfs,git push 被拒绝

git - git Android Studio 使用的 ssh-key

Git 克隆致命

python - 使用 Git 部署到我的服务器

git - 找出 GitHub 存储库的分支来源

git - 在不克隆 gitolite repo 的情况下安装 gitolite

Git 显示提交的标签