树中的git分支的输出就像时尚

现在,当我input“git分支”

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

我更喜欢的是如果“git分支”将我的输出列在fasion这样的树中,像下面这样的事情:

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

在这里,富和酒吧是从主人分支的; foo1&foo2从foo分支; bar4从酒吧分支。

这很容易完成?

[只有命令行工具。 这需要符合我的zsh / vim工作stream程。]

下面的答案使用git log

我在2009年提到了一个类似的方法:“ 无法在terminal上显示Git树 ”:

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

但我一直在使用的是“ 如何使用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工具也可以提供帮助 。 例:

 $ git wtf Local branch: master [ ] NOT in sync with remote (needs push) - Add before-search hook, for shortcuts for custom search queries. [4430d1b] (edwardzyang@...; 7 days ago) Remote branch: origin/master (git@gitorious.org: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] (wmorgan-sup@...; 2 days ago) [ ] labels-before-subj is NOT merged in (1 commit ahead) - put labels before subject in thread index view [790b64d] (marka@...; 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显示你:

  • 如果你的分支与远程仓库相关,如果它是追踪分支。
  • 如果您的分支与非function(“版本”)分支相关,如果它是function分支。
  • 如果您的分支与function分支相关,如果它是版本分支

这不是你所要求的,但是

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

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

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

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

我通过在〜/ .gitconfig文件中包含这些别名来使用它:

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

编辑:更新build议的日志命令/别名使用更简单的选项标志。

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

以下示例还显示了提交父项:

 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'