在日志中显示所有分支(但不包括暂存区)的Git命令

103
我有一个Git别名,它的扩展是:
git log --graph --oneline --all --decorate
根据man git log,有一些可疑的选项:--not--branches;但我无法使其正常工作。
我应该如何编辑以隐藏stash? FYI:根据已接受的答案评论,我的.gitconfig别名现在看起来像这样:
[alias]
    l = log --branches --remotes --tags --graph --oneline --decorate --notes HEAD
3个回答

141

不要使用--all,然后尝试过滤存储库中的stash,而是从一开始就不包含它们:

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

试图在之后过滤存储库所带来的主要问题是,如果该存储库是该分支上最新的提交(因为尽管它不是该分支的head,但它仍然是最近的后代),则实际上可以从日���中过滤掉整个分支,这不是您想要的。


2
太好了!为了完整性,我会添加 --tags - cYrus
我怀疑 --tags 是多余的,因为没有标签应该是分支或远程的 head 的后代,尽管我还没有验证过。 - Andrew Marshall
5
刚刚尝试了一下:使用命令 git checkout -b test 创建并切换到名为 "test" 的分支;添加一个提交记录;使用命令 git tag foo 打上名为 "foo" 的标签;使用命令 git checkout master 切换回主分支;使用命令 git branch -D test 删除名为 "test" 的分支。标签已经存在,但如果不加上 --tags 参数将无法显示。 - cYrus
3
一个小的补充 -- 你需要在结尾加上 HEAD。否则,如果你处于脱离HEAD模式并且没有其他引用指向HEAD提交,那么你在图表中看不到它。 - mziwisky

15

我的昵称:

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

在这种情况下,您将能够使用这些表单,而无需显示stash:

  • git l 用于当前分支
  • git l feature234 用于特定分支
  • git l --all 用于整个历史记录

来自手册:

--exclude=<glob pattern>

不包括与下一个--all、--branches、--tags、--remotes或--glob匹配的引用。


9
注意参数的顺序很重要:--all --exclude=refs/stash 仍然会包括stash,而 --exclude=refs/stash --all 将正确地将其排除。 - Mikhail Burshteyn

5
请注意,安德鲁的回答不适用于隐藏 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 - gavenkoa

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接