我在自己的机器上单独使用Git,我发现很难维护所有分支和提交的心理模型。我知道我可以通过git日志查看提交历史,但是有没有一种方法可以查看整个分支地形,就像这些ASCII映射一样,似乎到处都在用它来解释分支?

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

感觉就像有人来找我的存储库时,很难弄清楚到底发生了什么。

我猜我是受到了AccuRev的流媒体浏览器的影响…


当前回答

一个很好的基于web的工具是ungit。它可以运行在Node.js和Git支持的任何平台上。有一个视频是关于它是如何为那些发现这类事情比阅读更容易的人工作的……

其他回答

我喜欢,用git日志,做:

 git log --graph --oneline --branches

(还有——all,用于查看远程分支)

与最新Git版本的配合:自1.6.3以来引入(2009年5月7日星期四)

“——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次提交通常就足够了。

我通常用

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) Manual 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 successfully
| *   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

使用git log——graph或gitk。(两者都接受——all,这将显示所有分支,而不仅仅是当前的分支。)

对于分支名称和紧凑视图,尝试:

git log --graph --decorate --oneline

对于Linux来说,Gitg是一个很棒的工具,类似于OS x的Gitx。只需在命令行上从存储库的树结构中某处运行' Gitg '(与Gitx相同)。

我发现全局图很有用。

它使用dot/Graphviz创建了漂亮的2D图形,而不是gitk和朋友生成的相当线性的“一维”视图。使用-i选项,它显示分支点和合并提交,但省略了中间的所有内容。