显示 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:04:00  来源:igfitidea点击:

Showing Git branch structure

gitbranchgit-branch

提问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 logcan 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"

alt text

替代文字

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/mastercommit)

(使用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-decorationoption, 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 --allyet.

也许我错过了一些东西,但似乎没有人提到过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

gitxif you are on a macOS

gitx如果你使用的是 macOS

smartgitfor macOS or Windows (but i have not used it)

适用于 macOS 或 Windows 的smartgit(但我没有使用过)

git-guito use the native git gui (cross-platform)

git-gui使用原生 git gui(跨平台)

回答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 wtfwhich is an add on script by William Morgan: http://git-wt-commit.rubyforge.org/

要获取有关特定分支如何与存储库和远程服务器中的其他分支相关的更多信息,您可以使用git wtfWilliam 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)。