简体   繁体   English

显示 Git 分支结构

[英]Showing Git branch structure

Is there a way to show only the branch structure in Git?有没有办法只显示 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.我想 git-log 可能是答案,但我找不到任何只显示分支提交的开关。 This along with "--graph --branches --oneline --all" could do the trick.这与“--graph --branches --oneline --all”一起可以解决问题。

EDIT: I'm looking for a way to do this in Ubuntu.编辑:我正在寻找一种在 Ubuntu 中执行此操作的方法。

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ębski recommands adding the option --simplify-by-decoration , see his answer .注意: Jakub Narębski 建议添加选项--simplify-by-decoration ,请参阅他的回答

Perhaps what you want is --simplify-by-decoration option, see git log documentation:也许您想要的是--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

也许我错过了一些东西,但似乎还没有人提到gitk --all

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"

gitx if you are on a macOS gitx如果你使用的是 macOS

smartgit for macOS or Windows (but i have not used it)适用于 macOS 或 Windows 的smartgit (但我没有使用过)

git-gui to use the native git gui (cross-platform) git-gui使用原生 git gui(跨平台)

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 (git@gitorious.org: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)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM