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

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

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

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


当前回答

Git内置的工具(没有附加组件)具有日期时间格式

现有的答案都没有显示如何使用内置的git日志工具更改日期-时间格式。由于文档对这个特性有点迟钝,我添加了两个别名作为示例。

git树-所有提交的时间戳日志

# Tools for analyzing the merge history of a repo using tree-like graphics
[alias]
    tree = log --no-show-signature --graph --date=format-local:%H:%M:%S --all \
        --pretty="'%C(#ffe97b ul)%h%C(reset) %C(#568ea6)%cs %C(#305f72)%cd%C(reset)%C(auto)%d%C(reset) %s %C(yellow)(%C(reset)%C(#1abc9c)%an%C(reset)%C(yellow),%C(reset) %C(#007055)%cr%C(reset)%C(yellow))%C(reset)'"

git树。分支——所有分支/标签提交的时间戳日志

# Some refinements to normal 'git tree' output for alternative perspectives.
[alias "tree"]
    branches = tree --simplify-by-decoration

颜色代码

Spec Color Style
Commit ID Yellow Underline
Commit date Dark Blue
Commit time Light Blue
Commit message White
Commit Author Green
Commit relative date Dark Green
Remote branches Red
Local branches Purple
Tags Pink Underline

其他回答

看看SmartGit吧。它让我想起了TortoiseHg分支可视化,并且它是免费的非商业用途。

我发现难以置信的是,在许多答案中,它没有提到Gitviz,可用于windows /Linux/Mac 除了提供分支和提交的2d视图外,它还侦听git命令并自行修改图形。

我使用以下别名。

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

它在配色方案中比我上面看到的别名有更多的信息。它似乎也很常见,所以你可能有机会在别人的环境中存在,或者可以在对话中提到它而不需要解释。

在Git lola中有截图和完整的描述。

TortoiseGit有一个叫做“修订图”的工具。如果你在Windows上,它很容易右键单击你的仓库→Tortoise Git→修订图。

我想分享我的git日志命令的压缩预设: (绿色是我的默认控制台颜色)

它被设计成尽可能紧凑和像表格一样(没有增加任何多余的空间),同时仍然有信息和易于阅读。这基本上是Git默认使用的中型格式的压缩版本。

特点:

固定物品位置; 提交哈希和引用名称的默认颜色; 提交作者日期为本地时区; 提交消息被包装成128个字符并缩进; 扩展提交消息也会显示(如果有的话),并删除任何尾随换行符。


您可以使用以下命令将其添加到配置文件中: (注意他们会改变所有git日志格式的日期格式!)

$ git config --global log.date 'format-local:%d %b %Y %H:%M'
$ git config --global pretty.compact '%C(auto)%h %C(cyan)%<(17,trunc)%an%C(auto) %D%n        %C(cyan)%ad%C(auto) %w(128,0,26)%s%w(0,0,26)%+b%-(trailers:key=FAKE)'

... 然后像这样使用它(使用——graph,——all或任何其他选项):

$ git log --graph --pretty=compact

如果你也想让它默认,你可以用这个命令:

$ git config --global format.pretty compact

或者如果你喜欢别名:

$ git config --global alias.logc "log --date=format-local:'%d %b %Y %H:%M' --pretty='%C(auto)%h %C(cyan)%<(17,trunc)%an%C(auto) %D%n        %C(cyan)%ad%C(auto) %w(128,0,26)%s%w(0,0,26)%+b%-(trailers:key=FAKE)'"

如果您想做任何更改,请参阅git日志参考的PRETTY FORMATS部分。