首页 文章

在git中可视化分支拓扑

提问于
浏览
730

我在自己的机器上独立玩git,我发现很难维护我所有分支和提交的心理模型 . 我知道我可以做一个 git log 从我所在的地方查看提交历史,但是有没有办法看到整个分支地形,就像这些ascii Map 似乎随处可用来解释分支?

.-A---M---N---O---P
     /     /   /   /   /
    I     B   C   D   E
     \   /   /   /   /
      `-------------'

只是觉得有人出现并试图拿起我的存储库会很难确定正在发生的事情 .

我想我'm influenced by AccuRev' s stream browser ...

28 回答

  • 22

    一个很好的基于Web的工具是ungit . 它运行在node.js和git支持的任何平台上 . 对于那些发现比阅读更容易的事情的人来说,它有一个如何运作......

    enter image description here

  • 0

    我们可以让它变得更复杂吗?

    如何简单的git log --all --decorate --oneline --graph(记得A Dog = --All --Decorate --Oneline --Graph)

  • 443

    git log --graphgitk . (两者都接受 --all ,它将显示所有分支而不是当前分支 . )

    Edit: 对于分支名称和紧凑视图,请尝试: git log --graph --decorate --oneline

  • 358

    我经常使用

    git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"
    

    使用颜色(如果你的shell是Bash):

    git log --graph --full-history --all --color \
            --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"
    

    这将打印基于文本的表示,如下所示:

    * 040cc7c       (HEAD, master) Mannual is NOT built by default
    * a29ceb7       Removed offensive binary file that was compiled on my machine and was hence incompatible with other machines.
    | * 901c7dd     (cvc3) cvc3 now configured before building
    | * d9e8b5e     More sane Yices SMT solver caller
    | | * 5b98a10   (nullvars) All uninitialized variables get zero inits
    | |/
    | * 1cad874     CFLAGS for cvc3 to work succesfully
    | *   1579581   Merge branch 'llvm-inv' into cvc3
    | |\
    | | * a9a246b   nostaticalias option
    | | * 73b91cc   Comment about aliases.
    | | * 001b20a   Prints number of iteration and node.
    | |/
    |/|
    | * 39d2638     Included header files to cvc3 sources
    | * 266023b     Added cvc3 to blast infrastructure.
    | * ac9eb10     Initial sources of cvc3-1.5
    |/
    * d642f88       Option -aliasstat, by default stats are suppressed
    

    (你可以使用 git log --format=oneline ,但它会将提交消息绑定到数字,看起来不那么漂亮恕我直言) .

    要为此命令创建快捷方式,您可能需要编辑 ~/.gitconfig 文件:

    [alias]
      gr = log --graph --full-history --all --color --pretty=tformat:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s%x20%x1b[33m(%an)%x1b[0m"
    

    但是,正如注释中的Sodel the Vociferous注释,这种长格式化命令很难记忆 . 通常,这不是问题,因为您可能将其放入 ~/.gitconfig 文件中 . 但是,如果您有时必须登录到无法修改配置文件的远程计算机,则可以使用更简单但更快的类型版本:

    git log --graph --oneline
    
  • 209

    :我通常在我的 ~/.gitconfig 文件中抛出3个别名(以及4个快速使用的别名 - 别名):

    [alias]
        lg = !"git lg1"
        lg1 = !"git lg1-specific --all"
        lg2 = !"git lg2-specific --all"
        lg3 = !"git lg3-specific --all"
    
        lg1-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)'
        lg2-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n''          %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'
        lg3-specific = log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset) %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)%n''          %C(white)%s%C(reset)%n''          %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)'
    

    git lg / git lg1 看起来像这样:

    git lg1

    git lg2 看起来像这样:

    git lg2

    git lg3 看起来像这样:

    git lg3

    注意:答案在stackoverflow.com/questions/1057564/pretty-git-branch-graphs上复制并改进了答案,因为它在这里比在那里更合适 . 由于历史原因,将副本留在另一个问题上 - 它现在已关闭,答案由一堆其他答案引用 .

  • 11

    对于这些配方中的任何一个(基于git log或gitk),您可以添加 --simplify-by-decoration 来折叠历史记录中不感兴趣的线性部分 . 这样可以立即显示更多的拓扑 . 我现在可以理解没有这个选项会难以理解的大历史!

    我觉得有必要发布这个因为它没有出现在关于可视化历史的大部分Stack Overflow问题中,并且我花了很多时间寻找 - 甚至在我知道我想要它之后!我终于在这个_1527017中找到了它 . Stack Overflow的第一次提及似乎是Antoine Pelisse的this answer .

  • 12

    Gitk 有时候我很难读 .

    enter image description here

    激励我写GitVersionTree .

    enter image description here

  • 5

    “99.999%的时间是按照 git lg 查看历史记录,而0.001%是 git log

    只想分享2个可能有用的日志别名 . (从.gitconfig配置)

    [Alias]
         lg = log --graph --pretty=format:'%Cred%h%Creset %ad %s %C(yellow)%d%Creset %C(bold blue)<%an>%Creset' --date=short
         hist = log --graph --full-history --all --pretty=format:'%Cred%h%Creset %ad %s %C(yellow)%d%Creset %C(bold blue)<%an>%Creset' --date=short
    
    • git lg 将看到当前的分支历史记录 .

    • git hist 将看到整个分支历史记录 .

  • 6

    我喜欢用git log做:

    git log --graph --oneline --branches
    

    (也用--all,用于查看远程分支)

    适用于最近的Git版本:介绍since 1.6.3Thu, 7 May 2009

    命令日志族的“--pretty = <style>”选项现在拼写为“--format = <style>” . 另外, - format =%formatstring是--pretty = tformat:%formatstring的简写 . “--oneline”是“--pretty = oneline --abbrev-commit”的同义词 .

    PS D:\git\tests\finalRepo> git log --graph --oneline --branches --all
    * 4919b68 a second bug10 fix
    * 3469e13 a first bug10 fix
    * dbcc7aa a first legacy evolution
    | * 55aac85 another main evol
    | | * 47e6ee1 a second bug10 fix
    | | * 8183707 a first bug10 fix
    | |/
    | * e727105 a second evol for 2.0
    | * 473d44e a main evol
    |/
    * b68c1f5 first evol, for making 1.0
    

    您还可以限制日志显示的范围(提交次数):

    PS D:\git\tests\finalRepo> git log --graph --oneline --branches --all -5
    * 4919b68 a second bug10 fix
    * 3469e13 a first bug10 fix
    * dbcc7aa a first legacy evolution
    | * 55aac85 another main evol
    | | * 47e6ee1 a second bug10 fix
    

    (仅显示最近5次提交)


    我不喜欢当前选择的解决方案是:

    git log --graph
    

    它显示了太多信息(当我只想查看快速摘要时):

    PS D:\git\tests\finalRepo> git log --graph
    * commit 4919b681db93df82ead7ba6190eca6a49a9d82e7
    | Author: VonC <vonc@laposte.net>
    | Date:   Sat Nov 14 13:42:20 2009 +0100
    |
    |     a second bug10 fix
    |
    * commit 3469e13f8d0fadeac5fcb6f388aca69497fd08a9
    | Author: VonC <vonc@laposte.net>
    | Date:   Sat Nov 14 13:41:50 2009 +0100
    |
    |     a first bug10 fix
    |
    

    gitk 很棒,但强迫我将shell会话留给另一个窗口,而快速显示最后n个提交通常就足够了 .

  • 895

    看看Gitkraken - 一个跨平台的GUI,以清晰的方式显示拓扑 .

    Topology

    这里有一些关于一些高级功能的快速video tutorial .

  • 10

    Gitg是一个很棒的Linux工具,类似于Gitx for OS X.只需在命令行中从存储库树结构中的某个位置运行'gitg'(与gitx相同) .

  • 2

    我发现"git-big-picture"非常有用:https://github.com/esc/git-big-picture

    它使用点/ graphviz而不是相当线性的“一维”创建漂亮的2D图形观看gitk和朋友的产生 . 使用-i选项,它显示分支点和合并提交,但不包括中间的所有内容 .

  • 1

    看看BranchMaster .

    我把它写成可视化复杂的分支结构,通过将它们之间的所有提交折叠成一行 . 数字表示提交的数量 .

    enter image description here

  • 7

    Giggle绘制好的图表

  • 40

    Tortoise Git有一个名为"Revision Graph"的工具 . 如果您只需右键单击您的仓库 - > Tortoise Git - > Revision Graph即可 .

  • 22

    我使用以下别名 .

    [alias]
        lol = log --graph --decorate --pretty=oneline --abbrev-commit
        lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
    

    它在配色方案中的信息多于我在上面看到的别名 . 它似乎也很常见,因此您可能有机会将其存在于其他环境中,或者能够在对话中提及它而无需解释它 .

    屏幕截图和完整描述:http://blog.kfish.org/2010/04/git-lola.html

  • 0

    没人提到 tig ?它不像"BranchMaster"那样折叠分支,但......

    它很快,在终端运行 .

    因为它是如此快速(键盘控制)你获得了一个很好的用户体验,它几乎像我的“ ls ”包含git存储库的目录 .

    https://jonas.github.io/tig/

    它有通常的快捷方式, / 搜索等 .

    The revision graph

    (ps . 它是这个截图背景中的终端,现在看起来更好,但是我的电脑拒绝截取屏幕截图,抱歉)

    (pps . 我也使用gitkraken并且具有非常清晰的可视化,但它比 tig 重得多)

  • 17

    我在 ~/.gitconfig 中有 git log 别名来查看图表历史记录:

    [alias]
    l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
    

    使用别名后, git l 将显示如下内容:

    enter image description here

    在Git 2.12中,您甚至可以使用log.graphColors配置选项自定义图形的线条颜色 .

    至于日志' format, it' s类似于--oneline,添加了 author name (尊重 .mailmap )和 relative author date . 请注意,Git> = 1.8.3支持 %C(auto) 语法,它告诉Git使用提交哈希的默认颜色等 .

  • 62

    我发现this blog post显示了一种简洁的方式:

    git log --oneline --abbrev-commit --all --graph --decorate --color
    

    我通常为上面的命令创建一个别名:

    alias gg='git log --oneline --abbrev-commit --all --graph --decorate --color'
    

    而且只需使用 gg .

  • 5

    我个人最喜欢的别名是.gitconfig,它是:

    graph = log --graph --color --all --pretty=format:"%C(yellow)%H%C(green)%d%C(reset)%n%x20%cd%n%x20%cn%x20(%ce)%n%x20%s%n"
    
  • 5

    对于Mac用户,结帐(没有双关语意)免费的开源工具GitUp:http://gitup.co/

    我喜欢图表的显示方式,它比我见过的其他一些工具更清晰 .

    该项目在这里:https://github.com/git-up/GitUp

    GitUp screenshot

  • 38

    如果您碰巧使用OS X,Gitx也是一款出色的可视化工具 .

  • 5

    老帖子,但退房SmartGit . 它非常提醒Tortoise HG分支可视化,它可以免费用于非商业用途 .

  • 6

    另一个git log命令 . 这个与 fixed-width columns

    git log --graph --pretty=format:"%x09%h | %<(10,trunc)%cd |%<(25,trunc)%d | %s" --date=short
    
  • 6

    对于那些使用VSCode text editor的人,请考虑D. Jayamanne的Git History Extension

    enter image description here

  • 45

    在Windows上,您可以使用一个非常有用的工具:git扩展 . 它是一个gui工具,使git操作非常简单 .

    它也是开源的 .

    http://gitextensions.github.io

  • 8

    我试过 --simplify-by-decoration 但是我的所有合并都没有显示出来 . 因此,我只是删除了 Headers 处没有""和"/"符号的行,同时始终保持行"("指示分支 . 显示分支历史记录时,我对提交注释一般不感兴趣,所以我也删除它们 . 我最终得到以下shell别名 .

    gbh () { 
        git log --graph --oneline --decorate "$@" | grep '^[^0-9a-f]*[\\/][^0-9a-f]*\( [0-9a-f]\|$\)\|^[^0-9a-f]*[0-9a-f]*\ (' | sed -e 's/).*/)/'
    }
    
  • 30

    Git官方网站招募了一些第三方平台特定的GUI工具 . 点击这里git GUI Tools for Linux Platform

    我使用 gitgGitKraken 用于linux平台 . 两者都很好理解提交树

相关问题