我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?
当前回答
虽然我有时使用gitg,但我总是回到命令行:
[alias]
# Quick look at all repositories
loggsa = log --color --date-order --graph --oneline --decorate --simplify-by-decoration --all
# Quick look at active branch (or refs pointed)
loggs = log --color --date-order --graph --oneline --decorate --simplify-by-decoration
# Extend look at all repo
logga = log --color --date-order --graph --oneline --decorate --all
# Extend look at active branch
logg = log --color --date-order --graph --oneline --decorate
# Look with the date
logda = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\" --all
logd = log --color --date-order --date=local --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ad%Creset %C(auto)%d%Creset %s\"
# Look with the relative date
logdra = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\" --all
logdr = log --color --date-order --graph --format=\"%C(auto)%h%Creset %C(blue bold)%ar%Creset %C(auto)%d%Creset %s\"
loga = log --graph --color --decorate --all
# For repositories without subject body commits (Vim repository, git-svn clones)
logt = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\"
logta = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all
logtsa = log --graph --color --format=\"%C(auto)%h %d %<|(100,trunc) %s\" --all --simplify-by-decoration
正如您所看到的,它几乎是一个按键保存别名,基于:
--颜色:清晰外观--图形:可视化父对象--日期顺序:回购最容易理解--装饰:谁是谁--oneline:很多时候你需要知道的关于提交--通过修饰来简化:初步了解的基础(仅标记、相关合并、分支)--all:保存带有或不带有此选项的所有别名的键击--date=relative(%ar):了解回购中的活动(有时分支机构很少在主服务器附近提交,但几个月前就提交了)
请参阅Git的最新版本(1.8.5及以上版本),您可以从装饰占位符%d中的%C(auto)中获益。
从这里开始,您只需要很好地理解gitrevisions,以过滤您需要的任何内容(比如master…develop,其中--简化合并可能有助于实现长期分支)。
命令行背后的强大功能是根据您的需要快速配置(了解存储库不是唯一的密钥日志配置,因此有时需要添加--numstat、--raw或--name状态)。在这里,git日志和别名快速、强大,(随着时间的推移)是您可以实现的最漂亮的图形。更重要的是,默认情况下通过寻呼机显示输出(更不用说),您可以始终快速搜索结果。不相信?您始终可以使用gitgraph等项目解析结果。
其他回答
gitdags构建在TikZ&PGF之上,是一个小型LaTeX包,它允许您轻松地生成矢量图形提交图等。
自动生成现有存储库的提交图不是gitdags的目的;它生成的图形仅用于教育目的。
我经常使用它为Git问题的答案生成图形,作为ASCII提交图形的替代:
如何在master上执行错误修复并将其集成到不太稳定的分支中?git是如何提交修改工作的?为什么在我运行“Git checkout origin/<branch>”后,Git会告诉我“当前不在任何分支”?将主分支合并到分支和将分支合并到主分支之间有什么区别?Git rebase--保留合并失败
下面是这样一个图表的示例,演示了简单的重新设置基础的效果:
\documentclass{article}
\usepackage{subcaption}
\usepackage{gitdags}
\begin{document}
\begin{figure}
\begin{subfigure}[b]{\textwidth}
\centering
\begin{tikzpicture}
% Commit DAG
\gitDAG[grow right sep = 2em]{
A -- B -- {
C,
D -- E,
}
};
% Tag reference
\gittag
[v0p1] % node name
{v0.1} % node text
{above=of A} % node placement
{A} % target
% Remote branch
\gitremotebranch
[origmaster] % node name
{origin/master} % node text
{above=of C} % node placement
{C} % target
% Branch
\gitbranch
{master} % node name and text
{above=of E} % node placement
{E} % target
% HEAD reference
\gitHEAD
{above=of master} % node placement
{master} % target
\end{tikzpicture}
\subcaption{Before\ldots}
\end{subfigure}
\begin{subfigure}[b]{\textwidth}
\centering
\begin{tikzpicture}
\gitDAG[grow right sep = 2em]{
A -- B -- {
C -- D' -- E',
{[nodes=unreachable] D -- E },
}
};
% Tag reference
\gittag
[v0p1] % node name
{v0.1} % node text
{above=of A} % node placement
{A} % target
% Remote branch
\gitremotebranch
[origmaster] % node name
{origin/master} % node text
{above=of C} % node placement
{C} % target
% Branch
\gitbranch
{master} % node name and text
{above=of E'} % node placement
{E'} % target
% HEAD reference
\gitHEAD
{above=of master} % node placement
{master} % target
\end{tikzpicture}
\subcaption{\ldots{} and after \texttt{git rebase origin/master}}
\end{subfigure}
\caption{Demonstrating a typical \texttt{rebase}}
\end{figure}
\end{document}
我刚刚编写了一个工具,它可以使用HTML/Ccanvas生成一个漂亮的Git提交图。
并提供一个jQuery插件,使其易于使用。
[GitHub]https://github.com/tclh123/commits-graph
预览:
我建议tighttps://github.com/jonas/tig,一个更好的Git命令行工具。
您可以使用Homebrew在macOS上安装tig:
$ brew install tig
$ tig
试试dita。它可以将任何ASCII图转换为图像。虽然它的设计没有考虑Git分支,但我对结果印象深刻。
源(txt文件):
+--------+
| hotfix |
+---+----+
|
--*<---*<---*
^
|
\--*<---*
|
+---+----+
| master |
+--------+
命令:
java -jar ditaa0_9.jar ascii-graph.txt
结果:
它还支持背景色、虚线、不同形状等。请参见示例。
我在~/.gitconfig中有这个git日志别名来查看图形历史:
[alias]
l = log --all --graph --pretty=format:'%C(auto)%h%C(auto)%d %s %C(dim white)(%aN, %ar)'
有了这一点,git l将输出如下内容:
在Git2.12+中,您甚至可以使用log.graphColors配置选项自定义图形的线条颜色。
至于日志的格式,它类似于--oneline,添加了作者名(尊重.mailmap)和相对作者日期。请注意,在Git>=1.8.3中支持%C(auto)语法,告诉Git使用提交散列等的默认颜色。
推荐文章
- 如何将git配置存储为存储库的一部分?
- 如何修改GitHub拉请求?
- 如何在Github和本地删除最后n次提交?
- 我如何调试git/git-shell相关的问题?
- 错误:无法使用rebase进行拉取:您有未分阶段的更改
- Git隐藏未缓存:如何把所有未分期的变化?
- 真实的恶魔
- 如何从另一个分支获得更改
- Git:权限被拒绝(publickey)致命-无法从远程存储库读取。克隆Git存储库时
- git reflog和log有什么区别?
- git推挂在Total line之后
- 重命名git子模块
- 结合Git存储库的前两次提交?
- Xcode 6 gitignore文件应该包括什么?
- 我如何从现有回购的分支创建一个新的GitHub回购?