显示 Git 分支结构

发布于 2024-09-18 09:19:30 字数 185 浏览 5 评论 0 原文

有没有办法只显示Git中的分支结构?有许多工具可以以图形方式显示提交,但在我的例子中,列表太长,以至于无法看到结构。我想 git-log 可能是答案,但我找不到任何仅显示分支提交的开关。这与“--graph --branches --oneline --all”一起可以解决问题。

编辑:我正在寻找一种在 Ubuntu 中执行此操作的方法。

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.

EDIT: I'm looking for a way to do this in Ubuntu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

只怪假的太真实 2024-09-25 09:19:30

我不确定你所说的“分支结构”是什么意思。
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

但如果你只想要不同的 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';'"

使用 列命令,此处仅适用于自上次 origin/master 提交以来的提交)

注意:Jakub Narębski 建议添加选项--simplify-by-decoration ,请参阅他的答案

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):

[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:

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)

Note: Jakub Narębski recommands adding the option --simplify-by-decoration, see his answer.

二智少女猫性小仙女 2024-09-25 09:19:30

也许您想要的是 --simplify-by-decoration 选项,请参阅 git log 文档:

--通过装饰来简化

   选择由某些分支或标签引用的提交。

所以它将是

git log --graph --simplify-by-decoration --all

或遵循 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

Perhaps what you want is --simplify-by-decoration option, see git log documentation:

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

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
甜是你 2024-09-25 09:19:30

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

Maybe I'm missing something, but nobody seems to have mentioned gitk --all yet.

枯寂 2024-09-25 09:19:30

基本解决方案是:

git log --graph --all

如果你想变得更奇特:

git log --graph --all --pretty=format:"%Cblue%h%Creset [%Cgreen%ar%Creset] %s%C(yellow)%d%Creset"

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"
糖粟与秋泊 2024-09-25 09:19:30

gitx 如果您使用的是 macOS

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

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

gitx if you are on a macOS

smartgit for macOS or Windows (but i have not used it)

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

我还不会笑 2024-09-25 09:19:30

要获取有关特定分支如何与存储库和远程中的其他分支相关的更多信息,您可以使用 git wtf ,这是 William Morgan 的附加脚本:http://git-wt-commit.rubyforge.org/

它生成如下摘要信息:(

$ 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]

示例取自上述 URL) 。

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/

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文