我在自己的机器上孤立地玩git,我发现很难维持一个所有分支和提交的心理模型。我知道我可以通过git log
来查看我所在的地方的提交历史,但有没有一种方法可以看到整个分支的地形,就像这些似乎到处都用来解释分支的ascii地图?
.-A---M---N---O---P
/ / / / /
I B C D E
\ / / / /
`-------------'
我只是觉得,如果有人来找我的仓库,会很难搞清楚到底发生了什么。
我想我是受AccuRev'的流浏览器影响...
我通常使用
git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"
带颜色(如果你的外壳是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
,但它会将提交信息与数字捆绑在一起,这看起来不那么漂亮IMHO)。)
为了给这个命令做一个快捷键,你可能想编辑你的~/.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
,来做。
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 <[email protected]>
| Date: Sat Nov 14 13:42:20 2009 +0100
|
| a second bug10 fix
|
* commit 3469e13f8d0fadeac5fcb6f388aca69497fd08a9
| Author: VonC <[email protected]>
| Date: Sat Nov 14 13:41:50 2009 +0100
|
| a first bug10 fix
|
`gitk'很好,但迫使我离开shell会话去看另一个窗口,而快速显示最后的n个提交往往就足够了。