【问题标题】:Showing Git branch structure显示 Git 分支结构
【发布时间】:2011-04-09 16:17:48
【问题描述】:

有没有办法在 Git 中只显示分支结构?有许多工具以图形方式显示提交,但在我的情况下,列表太长以至于无法看到结构。我猜 git-log 可能是答案,但我找不到任何只显示分支提交的开关。这与“--graph --branches --oneline --all”一起可以解决问题。

编辑:我正在寻找一种在 Ubuntu 中执行此操作的方法。

【问题讨论】:

标签: git branch git-branch


【解决方案1】:

我不确定您所说的“分支结构”是什么意思。
git log 可以帮助可视化通过提交创建的分支(参见 blog post):

[alias]
    lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

但如果你只想要不同的 HEAD 分支,你可以试试something along the lines of:

heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"

(使用column command,此处仅用于自上次origin/master 提交以来的提交)

注意:Jakub Narębski 建议添加选项--simplify-by-decoration,参见his answer

【讨论】:

  • 这非常接近(后一种解决方案),我只需将日期和 --branch 添加到命令中。否则它只显示当前分支。尽管它仍然没有遗漏不是头部的提交。我所说的“分支结构”是一种查看每个分支是从哪个分支创建的方法,但是使用此命令,我可以滚动列表(大约有 350 个提交)以查看发生了什么。
  • @Makis:如果您有最终命令,可以将其发布为答案:我很感兴趣(并将投票赞成)。然后,如果您愿意,您甚至可以接受自己的答案作为官方答案。
  • 我还在研究,明天我会回到办公室尝试理解结构。该 repo 是用 svn2git 创建的,我也不是 100% 确定 svn repo 是由这本书所创建的。
  • @Makis:尝试--simplify-by-decoration git-log 选项。
  • 这可以解决问题,谢谢!也感谢其他人的建议!
【解决方案2】:

也许您想要的是--simplify-by-decoration 选项,请参阅git log 文档:

--通过装饰简化

     被某个分支或标签引用的提交被选中。

原来如此

git log --graph --simplify-by-decoration --all

或关注VonC answer

git log --graph --simplify-by-decoration \
   --pretty=format:'%Cred%h%Creset-%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' \
   --abbrev-commit --date=relative

【讨论】:

  • 太好了,我错过了那个特定的选项。 +1
  • @VonC:这是一个相当新的选择;它出现在 git 版本 1.6.1
  • 1.6.1? git.kernel.org/?p=git/git.git;a=tags:星期四,2008 年 12 月 25 日,对我来说似乎是一辈子的事;)
  • 这非常接近,但它错过了多个分支的共同祖先但未命名为分支或标签的提交。
【解决方案3】:

也许我遗漏了什么,但似乎还没有人提到 gitk --all

【讨论】:

  • 我刚试过gitk --all --simplify-by-decoration,效果很好。 (那是 git 1.7.9.5 提供的 gitk)
【解决方案4】:

基本解决方案是:

git log --graph --all

如果你想变得更花哨:

git log --graph --all --pretty=format:"%Cblue%h%Creset [%Cgreen%ar%Creset] %s%C(yellow)%d%Creset"

【讨论】:

    【解决方案5】:

    gitx 如果您使用的是 macOS

    smartgit 适用于 macOS 或 Windows(但我没有使用过)

    git-gui 使用原生 git gui(跨平台)

    【讨论】:

    • 对不起,忘了说我用的是 Ubuntu。
    • git-gui(你的意思是 gitk,对吗?)对我不起作用 - 1. 它只显示你结帐的分支,我想要整个树。 2. 它显示了所有的提交,我只对分支结构感兴趣。
    • @ripper234 你可以使用gitk -a 显示所有分支
    【解决方案6】:

    要获取有关特定分支如何与您的存储库和远程中的其他分支相关的更多信息,您可以使用git wtf,这是 William Morgan 的附加脚本:http://git-wt-commit.rubyforge.org/

    它会生成如下摘要信息:

    $ git wtf
    Local branch: master
    [x] in sync with remote
    Remote branch: origin/master (git@gitorious.org:willgit/mainline.git)
    [x] in sync with local
    
    Feature branches:
    { } origin/experimental is NOT merged in (1 commit ahead)
        - some tweaks i'm playing around with [80e5da1]
    { } origin/dont-assume-origin is NOT merged in (1 commit ahead)
        - guess primary remote repo from git config instead of assuming "origin" [23c96f1]
    

    (取自上述网址的示例)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 2020-12-11
      • 2021-04-15
      • 2011-11-29
      • 2020-05-13
      • 2019-03-15
      • 1970-01-01
      相关资源
      最近更新 更多