在git中可视化分支拓扑

我在自己的机器上孤立地玩git,我发现很难保持我所有分支和提交的心智模式。 我知道我可以做一个git log来查看我所在的提交历史,但是有没有办法看到整个分支地形,就像这些ascii地图似乎在任何地方用于解释分支?

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

它只是觉得有人前来试图拿起我的存储库将难以确切发生的事情。

我想我受到AccuRev的流浏览器的影响......


git log --graphgitk 。 (双方还接受--all ,它会显示所有的分支,而不仅仅是当前的一个。)

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


我通常使用

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评论中的Vociferous笔记,这种长格式的命令很难记住。 通常,这不是问题,因为您可能会将其放入~/.gitconfig文件中。 但是,如果您有时必须登录到无法修改配置文件的远程计算机,则可以使用更简单但更快速的键入版本:

git log --graph --oneline

:我通常在我的~/.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上复制并改进答案的答案,因为它比这里更合适。 出于历史原因,在另一个问题上留下副本 - 现在已关闭,答案被其他一些答案所引用。

链接地址: http://www.djcxy.com/p/68739.html

上一篇: Visualizing branch topology in git

下一篇: Finding what git commit some code spawned from