我在自己的机器上单独使用Git,我发现很难维护所有分支和提交的心理模型。我知道我可以通过git日志查看提交历史,但是有没有一种方法可以查看整个分支地形,就像这些ASCII映射一样,似乎到处都在用它来解释分支?
.-A---M---N---O---P
/ / / / /
I B C D E
\ / / / /
`-------------'
感觉就像有人来找我的存储库时,很难弄清楚到底发生了什么。
我猜我是受到了AccuRev的流媒体浏览器的影响…
我有3个别名(为了方便使用,还有4个别名-别名),通常都放在~/中。gitconfig文件:
[alias]
lg = lg1
lg1 = lg1-specific --all
lg2 = lg2-specific --all
lg3 = 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)'
gitlg / gitlg1是这样的:
Git lg2是这样的:
git lg3是这样的:
值得注意的是,这并不意味着这是一个最终的解决方案——它只是一个模板,供您根据自己的喜好进行更改、添加和修复。如果你想使用这些,我的建议是:
将它们添加到你的.gitconfig中,
根据您的喜好定制(不同的颜色选择,2线和3线版本的不同线条安排,等等),
然后将副本保存到Gist或其他代码片段工具中,以便将来可以复制并粘贴到.gitconfigs中(当然,也可以选择版本控制您的dotfiles)。
注意:答案复制并改进了stackoverflow.com/questions/1057564/pretty-git-branch-graphs上的答案,因为在这里比在那里更合适。由于历史原因,把副本留在了另一个问题上——它现在已经关闭了,答案被一堆其他答案引用了。
我在~/中有这个git日志别名。查看图表历史记录:
[alias]
l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
别名设置好后,git l将显示如下内容:
在Git 2.12+中,您甚至可以使用日志自定义图形的线条颜色。graphColors配置选项。
至于日志的格式,它类似于——oneline,只是增加了作者名称(关于.mailmap)和相对作者日期。注意%C(auto)语法,它告诉Git使用默认的颜色来提交哈希,等等,在Git >= 1.8.3中是支持的。
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 |