现在,当我输入"git branch"
它以任意顺序列出我的分支。
我更喜欢的是,如果“git分支”列出了我的输出树一样的时尚,一些像:
master
|-- foo
|-- foo1
|-- foo2
|-- bar
|-- bar4
在这里,foo和bar是从master衍生出来的;Foo1和foo2是foo的分支;Bar4是bar的分支。
这容易做到吗?
[仅限命令行实用程序。这需要适合我的zsh/vim工作流程。
现在,当我输入"git branch"
它以任意顺序列出我的分支。
我更喜欢的是,如果“git分支”列出了我的输出树一样的时尚,一些像:
master
|-- foo
|-- foo1
|-- foo2
|-- bar
|-- bar4
在这里,foo和bar是从master衍生出来的;Foo1和foo2是foo的分支;Bar4是bar的分支。
这容易做到吗?
[仅限命令行实用程序。这需要适合我的zsh/vim工作流程。
当前回答
虽然不是你想要的,但是
git log --graph --simplify-by-decoration --pretty=format:'%d' --all
做得很好。它还显示标签和远程分支。这可能不是每个人都想要的,但我发现它很有用。通过装饰来简化是这里限制引用的一个大技巧。
我使用类似的命令来查看我的日志。我已经能够完全取代我的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
编辑:更新了建议的日志命令/别名,以使用更简单的选项标志。
其他回答
下面的答案使用git log:
我在2009年提到过一个类似的方法“无法在终端中显示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-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告诉你: 如果你的分支是一个跟踪分支,那么你的分支与远程回购是如何关联的。 你的分支如何与非特性(“版本”)分支相关联,如果它是一个特性分支的话。 如果是版本分支,你的分支与特性分支是如何关联的
下面的例子也显示了提交父节点:
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'
对于那些使用Github的人来说,他们有一个分支网络查看器,看起来更容易阅读
你可以使用一个叫做gitk的工具。
TLDR;使用git show-tree,或者git lg别名(我的首选)。
1. 在树视图中显示所有分支(包括远程分支)。
使用git show-tree:
注意:git的show-tree不是核心git的一部分。你必须安装它作为一个额外的实用程序,称为“git-extras”。在Linux Ubuntu上,我用sudo apt install git-extras来实现。在这里的安装说明中找到您的操作系统,并按照说明安装它:
在Ubuntu上测试:
# Install it
sudo apt install git-extras
# Run it:
git-show-tree
# OR (same thing)
git show-tree
这就产生了类似于这里2个被点赞最多的答案的效果。
来源:http://manpages.ubuntu.com/manpages/bionic/man1/git-show-tree.1.html
例子:
Man git show-tree显示如下示例:
EXAMPLES Output the commit history log for all branches as tree view: * 4b57684 (HEAD, develop) Merge branch upstream master. |\ | * 515e94a Merge pull request #128 from nickl-/git-extras-html-hyperlinks | |\ | | * 815db8b (nickl/git-extras-html-hyperlinks, git-extras-html-hyperlinks) help ronn make hyperlinks. | * | 7398d10 (nickl/develop) Fix #127 git-ignore won´t add duplicates. | |/ | | * ab72c1e (refs/stash) WIP on develop: 5e943f5 Fix #127 git-ignore won´t add duplicates. | |/ |/| * | 730ca89 (bolshakov) Rebase bolshakov with master |/ * 60f8371 (origin/master, origin/HEAD, master) Merge pull request #126 from agrimaldi/fix-changelog-last-tag * 9627780 (tag: 1.7.0) Release 1.7.0 * 2e53ff6 (tag: 1.6.0) Release 1.6.0 * bbd32d8 (tag: 1.5.1) Release 1.5.1 | * 6b6b758 (nickl/gh-pages, gh-pages) add example git-extras to gh-pages | * 19cfd11 (origin/gh-pages) Index page | | * 881a70e (tag: 1.5.0) Release 1.5.0 | |/ |/| * | 4db5ee0 (tag: 1.4.0) Release 1.4.0 * | 9b0bc89 (tag: 1.3.0) Release 1.3.0 * | be49961 (tag: 1.2.0) Release 1.2.0 * | c1d2dfc (tag: 1.1.0) Release 1.1.0 * | 4a56adb (tag: 1.0.0) Release 1.0.0 * | 948308b (tag: 0.9.0) Release 0.9.0 * | 40b131d (tag: 0.8.1) Release 0.8.1 * | 391431d (tag: 0.8.0) Release 0.8.0
下面是ardupilot repo上git show-tree的输出示例:
此外,如果你安装了arcanist(更正:安装了Uber的arcanist的分支-请参阅我的答案底部的安装说明),arc flow显示了一个漂亮的上游依赖关系树(即:之前通过arc flow new_branch或手动通过git branch设置-set-upstream-to=upstream_branch)。弧流输出示例:
主 └──graft-D999 └──new_feature_1 └──new_feature_2
我真的发现弧流视图漂亮和有用,所以我有这个(不活跃的,还没有功能)git树开源项目,我计划复制它的行为:https://github.com/ElectricRCAircraftGuy/git-tree。
2. 树枝:以“树状”的方式显示一根树枝:
# Show the currently-checked-out branch
git lg
# OR: show branch_name
git lg branch_name
您可以添加-p或——patch来显示更改的行:
git lg -p
# OR
git lg --patch
要安装git lg别名(来源:https://coderwall.com/p/euwpig/a-better-git-log):
git config --global alias.lg "log --color --graph \
--pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) \
%C(bold blue)<%an>%Creset' --abbrev-commit"
示例输出显示了sshfs repo上的fork和merge等内容:
奖励git技巧:
我如何知道我正在运行一个嵌套shell?-见这里标题为“奖励:总是在你的终端显示你的当前git分支你也在!”
相关:
“arc graft”和“arc patch”有什么区别?