2010-09-08 126 views
33

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

编辑:我正在寻找一种方法来做到这一点在Ubuntu。

+1

可能重复的[漂亮的git分支图](http://stackoverflow.com/questions/1057564/pretty-git-branch-graphs) – trblnc 2017-01-30 11:48:57

回答

30

我不知道你的意思是什么“分支结构”。
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" 

alt text

但是如果你只想要不同的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

+0

这非常接近(后一种解决方案),我只需将日期和 - 分支添加到命令。否则它只显示当前分支。尽管它仍然没有忽略不是头的提交。我所说的“分支结构”是一种从每个分支创建的分支中查看的方式,但通过此命令,我可以滚动列表(其中有大约350个提交)来查看发生了什么。 – Makis 2010-09-08 12:34:23

+0

@Makis:如果你有最后的命令,你可以把它作为答案发布:我感兴趣(并将它投票)。然后,如果你愿意,你甚至可以接受你自己的答案作为官方答案。 – VonC 2010-09-08 13:26:51

+0

我仍在研究它,明天我会回到办公室去尝试理解结构。回购是用svn2git创建的,我并不是100%确定svn回购是由该书提供的。 – Makis 2010-09-08 16:47:42

3

gitx,如果你是在Mac上

smartgit Mac和或Windoze(但我没有用它)

git-gui然后对Ubuntu

+0

对不起,忘了提及我使用Ubuntu。 – Makis 2010-09-08 10:57:40

+0

git-gui(你的意思是gitk,对吗?)对我不起作用 - 1.它只显示你结帐的分支,我想要整个树。它显示了所有提交,我只对分支结构感兴趣。 – ripper234 2011-05-27 15:04:32

+0

@ ripper234你可以使用'gitk -a'来显示所有分支 – 2016-03-24 20:28:16

1

要获得特定分支如何涉及你的资料库和遥控器等分支机构,则可以使用git wtf它是由威廉·摩根在脚本中添加更多的信息:http://git-wt-commit.rubyforge.org/

它产生像摘要信息:

$ git wtf 
Local branch: master 
[x] in sync with remote 
Remote branch: origin/master ([email protected]: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] 

(取自上述URL的示例)。

6

,基本解决方案是:

git log --graph --all 

如果你想获得更多的花哨:

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

也许你想要的是--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 
+0

非常好,我错过了那个特别的选择。 +1 – VonC 2010-09-10 04:18:40

+0

@VonC:这是一个相当新的选择;它出现在git版本1.6.1中 – 2010-09-10 09:25:35

+0

1.6.1? http://git.kernel.org/?p=git​​/git.git;a=tags:2008年12月25日,星期四,对我来说似乎是一辈子;) – VonC 2010-09-10 10:55:13

6

也许我失去了一些东西,但似乎没有人提到gitk --all呢。

+1

它也显示所有个人提交。 – 2012-02-22 14:54:46

+2

我刚刚尝试过'gitk --all - 简化了装饰,并且工作得很好。 (这是用git 1.7.9.5提供的gitk) – Rhubbarb 2013-10-15 17:41:28