显示 Git 分支结构
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3666953/
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
Showing Git branch structure
提问by Makis
Is there a way to show only the branch structure in Git? There are a number of tools that show the commits graphically, but in my case the list is so long that it's impossible to see the structure. I guess git-log could be the answer, but I can't find any switches that only show the branching commits. This along with "--graph --branches --oneline --all" could do the trick.
有没有办法只显示 Git 中的分支结构?有许多工具可以以图形方式显示提交,但在我的情况下,列表太长以至于无法看到结构。我想 git-log 可能是答案,但我找不到任何只显示分支提交的开关。这与“--graph --branches --oneline --all”一起可以解决问题。
EDIT: I'm looking for a way to do this in Ubuntu.
编辑:我正在寻找一种在 Ubuntu 中执行此操作的方法。
回答by VonC
I am not sure about what you mean by "branch structure".git log
can help visualize the branches made through commits (See this blog post):
我不确定您所说的“分支结构”是什么意思。git log
可以帮助可视化通过提交创建的分支(请参阅此博客文章):
[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"
But if you only wants the different HEAD branches, you could try something along the lines of:
但是如果你只想要不同的 HEAD 分支,你可以尝试一些类似的东西:
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';'"
(using the column command
, and here only for commits since the last origin/master
commit)
(使用column command
, 并且这里仅用于自上次origin/master
提交以来的提交)
Note: Jakub Nar?bskirecommands adding the option --simplify-by-decoration
, see his answer.
注意:Jakub Nar?bski 建议添加选项 --simplify-by-decoration
,请参阅他的回答。
回答by Jakub Nar?bski
Perhaps what you want is --simplify-by-decoration
option, see git logdocumentation:
也许您想要的是--simplify-by-decoration
选项,请参阅git log文档:
--simplify-by-decoration
Commits that are referred by some branch or tag are selected.
--简化装饰
选择由某个分支或标签引用的提交。
So it would be
所以它会
git log --graph --simplify-by-decoration --all
or following VonC answer
或跟随VonC 回答
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
回答by Benjol
Maybe I'm missing something, but nobody seems to have mentioned gitk --all
yet.
也许我错过了一些东西,但似乎没有人提到过gitk --all
。
回答by cmcginty
Basic solution is:
基本解决方案是:
git log --graph --all
If you want to get more fancy:
如果你想变得更花哨:
git log --graph --all --pretty=format:"%Cblue%h%Creset [%Cgreen%ar%Creset] %s%C(yellow)%d%Creset"
回答by PurplePilot
回答by Emil Sit
To get more information on how a particular branch relates to other branches in your repository and remotes, you can use git wtf
which is an add on script by William Morgan: http://git-wt-commit.rubyforge.org/
要获取有关特定分支如何与存储库和远程服务器中的其他分支相关的更多信息,您可以使用git wtf
William Morgan 的附加脚本:http: //git-wt-commit.rubyforge.org/
It produces summary information like:
它生成摘要信息,如:
$ 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]
(example taken from the above URL).
(示例取自上述 URL)。