【问题标题】:Git show all branches (but not stashes) in logGit在日志中显示所有分支(但不是存储)
【发布时间】:2012-02-24 19:56:33
【问题描述】:

我有一个 Git 别名,它扩展为:

git log --graph --oneline --all --decorate

根据man git log,有几个可疑选项:--not--branches;但我不能让它正常工作。

我应该如何编辑它以隐藏隐藏?


仅供参考:根据accepted questioncomment 我的.gitconfig 别名现在看起来像这样:

[alias]
    l = log --branches --remotes --tags --graph --oneline --decorate --notes HEAD

【问题讨论】:

    标签: git git-log git-stash


    【解决方案1】:

    不要先执行--all,然后尝试过滤掉存储,而是首先不要包含它们:

    git log --branches --remotes --tags --graph --oneline --decorate
    

    之后试图将它们过滤掉的主要问题是,如果存储是该分支上的最新提交(因为即使它不是分支的 head,它仍然是它的最新后代) ,它实际上可以从日志中过滤掉整个分支,这不是你想要的。

    【讨论】:

    • 太棒了!为了完整起见,我会添加--tags
    • 我怀疑--tags 是多余的,因为任何标签都不应该是分支或远程的head 的后代,尽管我还没有验证这一点。
    • 刚试过这个:git checkout -b test;添加了一个提交; git tag foo ; git checkout master ; git branch -D test。标签在那里,但如果没有--tags,它将不会显示。
    • 一个小补充——你应该在末尾添加HEAD。否则,如果您处于分离 HEAD 模式并且没有其他 ref 指向 HEAD 提交,您将不会在图中看到它。
    【解决方案2】:

    我的别名:

    [alias]
        l = log --oneline --decorate --graph --exclude=refs/stash
    

    在这种情况下,您将能够在不显示存储的情况下使用这些表单:

    • git l 当前分支
    • git l feature234 用于特定分支
    • git l --all 查看全部历史记录

    来自手册:

    --exclude=

    不要包含匹配下一个--all、--branches、--tags、--remotes 或--glob 否则会考虑的引用。

    【讨论】:

    • 请注意,参数的顺序很重要:--all --exclude=refs/stash 仍将包含存储,而--exclude=refs/stash --all 将正确排除它。
    【解决方案3】:

    请注意,Andrew's answer 不能用于隐藏 StGit1.) 分支 <branch>.stgit(来自 StGit 版本 0.15),否则会乱扔输出使其无法使用。

    目前我使用以下解决方案:

    $ git log --graph --oneline --decorate \
      $(git for-each-ref --format="%(refname)" refs/heads/ refs/remotes/ |
        grep -v "\.stgit$")
    

    1.) StGit ("Stacked Git") 为 Git 提供类似 Quilt/mq 的功能(即向/从堆栈推送/弹出补丁)。

    【讨论】:

    • 考虑使用--exclude。喜欢:git log --graph --exclude=refs/heads/*.stgit --exclude=refs/patches/* --exclude=refs/stash --all
    猜你喜欢
    • 2023-03-11
    • 2021-02-26
    • 2010-12-15
    • 1970-01-01
    • 2013-02-05
    • 2014-04-27
    • 2021-04-30
    • 1970-01-01
    相关资源
    最近更新 更多