像时尚一样在树中输出 git branch
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2421011/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Output of git branch in tree like fashion
提问by anon
Right now, when I type "git branch"
现在,当我输入“git branch”
it lists my branches in an arbitrary order.
它以任意顺序列出我的分支。
What I would prefer would be if "git branch" listed my output in a tree like fasion, somethign like:
我更喜欢的是,如果“git branch”将我的输出列在像 fasion 这样的树中,例如:
master
|-- foo
|-- foo1
|-- foo2
|-- bar
|-- bar4
Where here, foo & bar were branched from master; foo1 & foo2 were branched from foo; bar4 was branched from bar.
在这里,foo & bar 是从 master 分支出来的;foo1 和 foo2 是从 foo 分支出来的;bar4 是从 bar 分支出来的。
Is this easy to accomplish?
这容易实现吗?
[Command line utilities only. This needs to fit into my zsh/vim workflow.]
[仅限命令行实用程序。这需要适合我的 zsh/vim 工作流程。]
回答by VonC
The answer belowuses git log
:
I mentioned a similar approach in 2009 with "Unable to show a Git tree in terminal":
我在 2009 年的“无法在终端中显示 Git 树”中提到了类似的方法:
git log --graph --pretty=oneline --abbrev-commit
But the full one I have been using is in "How to display the tag name and branch name using git log --graph" (2011):
但我一直在使用的完整版本在“如何使用 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
Original answer (2010)
原始答案 (2010)
git show-branch --list
comes close of what you are looking for (with the topo order)
git show-branch --list
接近您正在寻找的内容(使用拓扑顺序)
--topo-order
By default, the branches and their commits are shown in reverse chronological order.
This option makes them appear in topological order (i.e., descendant commits are shown before their parents).
默认情况下,分支及其提交按时间倒序显示。
此选项使它们按拓扑顺序出现(即,后代提交显示在其父项之前)。
But the tool git wtfcan help too. Example:
$ 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 ([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] (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
shows you:
- How your branch relates to the remote repo, if it's a tracking branch.
- How your branch relates to non-feature ("version") branches, if it's a feature branch.
- How your branch relates to the feature branches, if it's a version branch
git-wtf
向您展示:
- 您的分支与远程仓库的关系(如果它是一个跟踪分支)。
- 您的分支与非功能(“版本”)分支的关系(如果它是功能分支)。
- 您的分支与功能分支的关系(如果它是版本分支)
回答by nocash
It's not quite what you asked for, but
这不是你所要求的,但是
git log --graph --simplify-by-decoration --pretty=format:'%d' --all
does a pretty good job. It shows tags and remote branches as well. This may not be desirable for everyone, but I find it useful. --simplifiy-by-decoration
is the big trick here for limiting the refs shown.
做得很好。它也显示标签和远程分支。这可能不是每个人都想要的,但我觉得它很有用。--simplifiy-by-decoration
是这里限制显示的参考的大技巧。
I use a similar command to view my log. I've been able to completely replace my gitk
usage with it:
我使用类似的命令来查看我的日志。我已经能够gitk
用它完全取代我的用法:
git log --graph --oneline --decorate --all
I use it by including these aliases in my ~/.gitconfig file:
我通过在 ~/.gitconfig 文件中包含这些别名来使用它:
[alias]
l = log --graph --oneline --decorate
ll = log --graph --oneline --decorate --branches --tags
lll = log --graph --oneline --decorate --all
Edit:Updated suggested log command/aliases to use simpler option flags.
编辑:更新了建议的日志命令/别名以使用更简单的选项标志。
回答by Ben
The following example shows commit parents as well:
以下示例也显示了提交父项:
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'
回答by Vladimir Prudnikov
You can use a tool called gitk
.
您可以使用名为gitk
.
回答by Gabriel Staples
Tested on Ubuntu:
在 Ubuntu 上测试:
sudo apt install git-extras
git-show-tree
This produces an effect similar to the 2 most upvoted answers here.
这会产生类似于此处 2 个最受好评的答案的效果。
Source: http://manpages.ubuntu.com/manpages/bionic/man1/git-show-tree.1.html
来源:http: //manpages.ubuntu.com/manpages/bionic/man1/git-show-tree.1.html
Also, if you have arcanistinstalled (correction: Uber's fork of arcanistinstalled--see the bottom of this answer herefor installation instructions), arc flow
shows a beautiful dependency tree of upstream dependencies (ie: which were set previously via arc flow new_branch
or manually via git branch --set-upstream-to=upstream_branch
).
此外,如果您安装了Arcanist(更正:安装了Uber 的 Arcanist 分支——有关安装说明,请参阅此答案的底部以获取安装说明),arc flow
显示上游依赖项的漂亮依赖树(即:之前通过arc flow new_branch
或手动设置通过git branch --set-upstream-to=upstream_branch
)。
Bonus git tricks:
额外的 git 技巧:
- How do I know if I'm running a nested shell?- see section here titled "Bonus: always show in your terminal your current
git branch
you are on too!"
- 我怎么知道我是否正在运行一个嵌套的 shell?- 请参阅此处标题为“奖励:始终在您的终端中显示您当前所在的
git branch
部分!”
Related:
有关的:
回答by kip2
For those who use Github, they have a branch network viewerthat seems easier to read
对于使用 Github 的人来说,他们有一个看起来更容易阅读的分支网络查看器