2010-03-10 50 views
88

现在,当我输入“git branch”输出的git树枝像时尚

它以任意顺序列出我的分支。

我宁愿是,如果“混帐分支”上市我像FASION树输出,somethign像:

master 
|-- foo 
    |-- foo1 
    |-- foo2 
|-- bar 
    |-- bar4 

凡在这里,FOO &酒吧从主分枝; foo1 & foo2从foo分支; bar4从酒吧分支。

这很容易实现吗?

[仅命令行实用程序。这就需要适应我的zsh/vim的工作流程]

回答

106

answer below使用git log

2009年,我提到了类似的做法与 “Unable to show a Git tree in terminal”:

git log --graph --pretty=oneline --abbrev-commit 

但完整的我有一直使用处于 “How to display the tag name and branch name using git log --graph”(2011):

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

git lgb 

原来的答复(2010)

git show-branch --list接近你在找什么(用TOPO顺序)

--topo-order 

默认情况下,分支机构和他们提交显示按时间倒序排列。
此选项使它们以拓扑顺序显示(即,后代提交显示在其父母之前)。

但是工具git wtf可以help too。例如:

$ git wtf 
Local branch: master 
[ ] NOT in sync with remote (needs push) 
    - Add before-search hook, for shortcuts for custom search queries. [4430d1b] ([email protected]; 7 days ago) 
Remote branch: origin/master ([email protected]:sup/mainline.git) 
[x] in sync with local 

Feature branches: 
{ } origin/release-0.8.1 is NOT merged in (1 commit ahead) 
    - bump to 0.8.1 [dab43fb] ([email protected]; 2 days ago) 
[ ] labels-before-subj is NOT merged in (1 commit ahead) 
    - put labels before subject in thread index view [790b64d] ([email protected]; 4 weeks ago) 
{x} origin/enclosed-message-display-tweaks merged in 
(x) experiment merged in (only locally) 

NOTE: working directory contains modified files 

git-wtf表明您:

  • 您的分支如何涉及到远程回购,如果它是一个跟踪分支。
  • 您的分支如何与非特征(“版本”)分支相关,如果它是特征分支。
  • 您的分支如何涉及功能分支,如果它是一个版本分支
+0

被使用,显示了作者的电子邮件以及使用%AE你​​的漂亮格式的变化。另外我更喜欢用“sl”来称呼别名,以类似于hg的智能日志。 – fiorix 2017-12-16 09:40:58

+0

非常感谢'git-wtf'工具的链接,它非常有用。似乎基本上打破了我从盯着一个奇特的“git日志”树中得出的结论,但总结得很好。 – 2018-02-18 19:50:31

8

您可以使用一个名为gitk工具。

+0

我喜欢gitk,但我没有在Mac中找出'''gitk'''。如果您有任何建议,请告诉我。我开始使用'''Github Desktop''',但喜欢在命令行上工作。 – 2016-07-13 18:44:52

105

这不是你问了好东西,但

git log --graph --simplify-by-decoration --pretty=format:'%d' --all 

做了很好的工作。它还显示标签和远程分支。这可能不适合每个人,但我觉得它很有用。 --simplifiy-by-decoration是限制显示参数的重要手段。

我使用类似的命令来查看我的日志。我已经能够用它完全取代我gitk用法:

[alias] 
    l = log --graph --oneline --decorate 
    ll = log --graph --oneline --decorate --branches --tags 
    lll = log --graph --oneline --decorate --all 

编辑:更新日志建议

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

我通过在我的〜/的.gitconfig文件这些别名使用命令/别名使用更简单的选项标志。

+1

海事组织这是这里最好的答案,但我认为[SourceTree](http://sourcetreeapp.com/)或gitk之类的是这种事情的方式。 – JaKXz 2014-09-03 21:23:43

+0

这将显示原点处的分支。有什么方法可以让本地分行显示? – Jeff 2015-01-13 16:05:53

+0

@Jeff用'--branches --tags'代替'--all'可能会做到这一点。 – nocash 2015-02-20 22:03:51

7

下面的例子显示提交父母以及:

git log --graph --all \ 
--format='%C(cyan dim) %p %Cred %h %C(white dim) %s %Cgreen(%cr)%C(cyan dim) <%an>%C(bold yellow)%d%Creset' 
+1

在Windows上不起作用。 – 2015-09-04 20:08:44