我在自己的机器上单独使用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日志,做:
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次提交通常就足够了。