我在自己的机器上独立玩git,我发现很难维护我所有分支和提交的心理模型.我知道我可以做一个git log从我所在的地方查看提交历史,但有没有办法看到整个分支地形,像这些ascii地图似乎在任何地方用来解释分支?
.-A---M---N---O---P
/ / / / /
I B C D E
\ / / / /
`-------------'
Run Code Online (Sandbox Code Playgroud)
只是觉得有人出现并试图拿起我的存储库会很难确定正在发生的事情.
我想我受AccuRev 流媒体浏览器的影响 ......
jro*_*way 1022
git log --graph或gitk.(两者都接受--all,它将显示所有分支而不仅仅是当前分支.)
编辑:
对于分支名称和紧凑视图,请尝试:git log --graph --decorate --oneline
P S*_*ved 473
我经常使用
git log --graph --full-history --all --pretty=format:"%h%x09%d%x20%s"
Run Code Online (Sandbox Code Playgroud)
使用颜色(如果你的shell是Bash):
git log --graph --full-history --all --color \
--pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"
Run Code Online (Sandbox Code Playgroud)
这将打印基于文本的表示,如下所示:
* 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
Run Code Online (Sandbox Code Playgroud)
(你可以使用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"
Run Code Online (Sandbox Code Playgroud)
然而,正如Vociferous在评论中所说的那样,这种长格式化命令难以记忆.通常,这不是问题,因为您可以将其放入~/.gitconfig文件中.但是,如果您有时必须登录到无法修改配置文件的远程计算机,则可以使用更简单但更快的类型版本:
git log --graph --oneline
Run Code Online (Sandbox Code Playgroud)
Sli*_*son 413
我有3个别名(和4个别名 - 别名,以便快速使用),我通常会在我的~/.gitconfig文件中抛出:
[alias]
lg = !"git lg1"
lg1 = !"git lg1-specific --all"
lg2 = !"git lg2-specific --all"
lg3 = !"git 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)'
Run Code Online (Sandbox Code Playgroud)
git lg/ git lg1看起来像这样:

git lg2 看起来像这样:

并且git lg3看起来是这样的:

注意:答案在stackoverflow.com/questions/1057564/pretty-git-branch-graphs上复制并改进了答案,因为它在这里比在那里更合适.由于历史原因,将副本留在另一个问题上 - 它现在已关闭,答案由一堆其他答案引用.
And*_*rew 226
对于这些配方中的任何一个(基于git log或gitk),您可以添加--simplify-by-decoration以折叠历史记录中不感兴趣的线性部分.这样可以立即显示更多的拓扑.我现在可以理解没有这个选项会难以理解的大历史!
我觉得有必要发布这个,因为它似乎并不像它应该的那样众所周知.它没有出现在关于可视化历史的大多数Stack Overflow问题中,并且我花了很多时间寻找 - 即使在我知道我想要它之后!我终于在这个Debian错误报告中找到了它.关于Stack Overflow的第一次提及似乎是Antoine Pelisse的回答.
che*_*sum 72
Gitk 有时我很难读.

激励我写GitVersionTree.

Yeo*_*Yeo 48
"我99.999%的时间都在寻找历史,git lg而0.001%是由git log"
只想分享2个可能有用的日志别名.(从.gitconfig配置)
[Alias]
lg = log --graph --pretty=format:'%Cred%h%Creset %ad %s %C(yellow)%d%Creset %C(bold blue)<%an>%Creset' --date=short
hist = log --graph --full-history --all --pretty=format:'%Cred%h%Creset %ad %s %C(yellow)%d%Creset %C(bold blue)<%an>%Creset' --date=short
Run Code Online (Sandbox Code Playgroud)
git lg 将看到当前的分支历史.git hist 将看到整个分支历史.Von*_*onC 43
我喜欢,git log做,做:
git log --graph --oneline --branches
Run Code Online (Sandbox Code Playgroud)
(也用--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
Run Code Online (Sandbox Code Playgroud)
您还可以限制日志显示的范围(提交次数):
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
Run Code Online (Sandbox Code Playgroud)
(仅显示最近5次提交)
我不喜欢当前选择的解决方案是:
git log --graph
Run Code Online (Sandbox Code Playgroud)
它显示了太多信息(当我只想查看快速摘要时):
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
|
Run Code Online (Sandbox Code Playgroud)
gitk 很棒,但强迫我将shell会话留给另一个窗口,而快速显示最后n个提交通常就足够了.
pyl*_*ang 42
看看Gitkraken--一个跨平台的GUI,以清晰的方式显示拓扑.
这是一些关于一些高级功能的快速视频教程.
Fra*_*eld 24
我发现"git-big-picture"非常有用:https://github.com/esc/git-big-picture
它使用dot/graphviz创建漂亮的2D图形,而不是gitk和朋友生成的相当线性的"一维"视图.使用-i选项,它显示分支点和合并提交,但不包括中间的所有内容.
str*_*yer 21
我把它写成可视化复杂的分支结构,通过将它们之间的所有提交折叠成一行.数字表示提交的数量.

klm*_*123 20
我正在使用Visual Studio Code编辑器,我发现自己对mhutchie 制作的Git Graph扩展非常满意。(而且我并不孤单,该扩展程序有 100 万用户!)。
如果您碰巧喜欢该编辑器,则只需转到扩展选项卡(左侧中间的小隔间)并输入“Git Graph”并安装
要使用它,请转到 Git 控制选项卡并按查看 Git 图表按钮
Chr*_*dam 15
Tortoise Git有一个名为"Revision Graph"的工具.如果您使用的是Windows,只需右键单击您的仓库 - > Tortoise Git - > Revision Graph即可.
wir*_*res 14
没有人提到过tig?它不像"BranchMaster"那样折叠分支,但是......
它很快,在终端运行.
因为它是如此快速(+键盘控制)你获得了一个很好的用户体验,它几乎像我的" ls"包含git存储库的目录.
它有通常的快捷方式,/搜索等.

(ps.它是这个截图背景中的终端,现在看起来更好,但是我的电脑拒绝截取屏幕截图,抱歉)
(pps.我也使用gitkraken并且具有非常清晰的可视化,但它比它重得多tig)
Lok*_*ist 12
我使用以下别名.
[alias]
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
Run Code Online (Sandbox Code Playgroud)
它在配色方案中的信息多于我在上面看到的别名.它似乎也很常见,因此您可能有机会将其存在于其他环境中,或者能够在对话中提及它而无需解释它.
有截图和完整描述:http: //blog.kfish.org/2010/04/git-lola.html
Sad*_*egh 11
我发现这篇博文显示了一个简洁的方法:
git log --oneline --abbrev-commit --all --graph --decorate --color
Run Code Online (Sandbox Code Playgroud)
我通常为上面的命令创建一个别名:
alias gl='git log --oneline --abbrev-commit --all --graph --decorate --color'
Run Code Online (Sandbox Code Playgroud)
而且只需使用gl.
Eug*_*ash 11
我有这个git log别名~/.gitconfig来查看图表历史记录:
[alias]
l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
Run Code Online (Sandbox Code Playgroud)
使用别名,git l将显示如下内容:
在Git 2.12 +中,您甚至可以使用log.graphColors配置选项自定义图形的线条颜色.
至于日志的格式,它--oneline与添加作者姓名(尊重.mailmap)和相对作者日期类似.请注意,%C(auto)Git> = 1.8.3支持语法,该语法告诉Git使用提交哈希的默认颜色等.
Edw*_*Tan 11
对于Mac用户,结帐(没有双关语)免费的开源工具GitUp:http://gitup.co/
我喜欢图表的显示方式,它比我见过的其他一些工具更清晰.
该项目在这里:https://github.com/git-up/GitUp
我个人最喜欢的别名是.gitconfig,它是:
graph = log --graph --color --all --pretty=format:"%C(yellow)%H%C(green)%d%C(reset)%n%x20%cd%n%x20%cn%x20(%ce)%n%x20%s%n"
Run Code Online (Sandbox Code Playgroud)
对于那些使用VSCode文本编辑器的人,请考虑D. Jayamanne 的Git History Extension:
另一个git log命令.这个有固定宽度的列:
git log --graph --pretty=format:"%x09%h | %<(10,trunc)%cd |%<(25,trunc)%d | %s" --date=short
Run Code Online (Sandbox Code Playgroud)
我想分享我的命令compact预设git log:(
绿色是我的默认控制台颜色)

它被设计得尽可能紧凑和像表格一样(不添加任何多余的空间),同时仍然提供丰富的信息且易于阅读。medium这基本上是Git 默认使用的格式的紧凑版本。
特征:
您可以使用以下命令将其添加到您的配置文件中:(请注意,它们将更改所有
格式的日期格式!) git log
$ 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)'
Run Code Online (Sandbox Code Playgroud)
...然后像这样使用它(使用--graph或--all任何其他选项):
$ git log --graph --pretty=compact
Run Code Online (Sandbox Code Playgroud)
如果您还想将其设置为默认值,可以使用以下命令来执行此操作:
$ git config --global format.pretty compact
Run Code Online (Sandbox Code Playgroud)
或者如果您喜欢别名:
$ git log --graph --pretty=compact
Run Code Online (Sandbox Code Playgroud)
如果您想进行任何更改,请参阅参考资料的“漂亮格式”部分git log。
由于文档在使用内置格式方面有点迟钝,因此这里还有两个开箱即用的示例别名。
\ngit tree\xe2\x80\x93 所有提交的时间戳日志# Tools for analyzing the merge history of a repo using tree-like graphics\n[alias]\n tree = log --no-show-signature --graph --date=format-local:%H:%M:%S --all \\\n --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)\'"\nRun Code Online (Sandbox Code Playgroud)\n\ngit tree.branches\xe2\x80\x93 所有分支/标签提交的时间戳日志# Some refinements to normal \'git tree\' output for alternative perspectives.\n[alias "tree"]\n branches = tree --simplify-by-decoration\nRun Code Online (Sandbox Code Playgroud)\n\n| 规格 | 颜色 | 风格 |
|---|---|---|
| 提交ID | 黄色的 | 强调 |
| 提交日期 | 深蓝 | |
| 提交时间 | 浅蓝色 | |
| 提交消息 | 白色的 | |
| 提交作者 | 绿色的 | |
| 提交相对日期 | 深绿色 | |
| 远程分支机构 | 红色的 | |
| 当地分支机构 | 紫色的 | |
| 标签 | 粉色的 | 强调 |
| 归档时间: |
|
| 查看次数: |
501857 次 |
| 最近记录: |