我见过一些书籍和文章中有一些非常漂亮的Git分支和提交的图表。如何制作Git历史的高质量可打印图像?
当前回答
git forest是一个优秀的Perl脚本,我已经使用了一年多,我几乎不再直接使用git log命令。
以下是我喜欢这个剧本的一些地方:
它使用Unicode字符在图形中绘制线条,使图形线条看起来更加连续。您可以将--reverse与图形输出相结合,这在常规gitlog命令中是不可能的。它在内部使用gitlog获取提交列表,因此传递给gitlog的所有选项也可以传递给该脚本。
我有一个使用git forest的别名,如下所示:
[alias]
tree = "forest --pretty=format:\"%C(red)%h %C(magenta)(%ar) %C(blue)%an %C(reset)%s\" --style=15 --reverse"
这是终端输出的外观:
其他回答
我建议tighttps://github.com/jonas/tig,一个更好的Git命令行工具。
您可以使用Homebrew在macOS上安装tig:
$ brew install tig
$ tig
我添加了三个自定义命令:gittree、gitstree和gitvtree。我会按顺序检查它们。
[alias]
tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n %C(black)[%cr]%C(reset) %x09%C(black)%an: %s %C(reset)'
使用gitstree和gitvtree,我使用Bash来帮助格式化。
[alias]
logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++ %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
stree = !bash -c '" \
while IFS=+ read -r hash time branch message; do \
timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\"); \
timelength=$(echo \"16+${#time}-${#timelength}\" | bc); \
printf \"%${timelength}s %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"\"; \
done < <(git logx && echo);"'
[alias]
logx = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset)+%C(dim black)(%cr)%C(reset)+%C(auto)%d%C(reset)++\n+++ %C(bold black)%an%C(reset)%C(black): %s%C(reset)'
vtree = !bash -c '" \
while IFS=+ read -r hash time branch message; do \
timelength=$(echo \"$time\" | sed -r \"s:[^ ][[]([0-9]{1,2}(;[0-9]{1,2})?)?m::g\"); \
timelength=$(echo \"16+${#time}-${#timelength}\" | bc); \
printf \"%${timelength}s %s %s %s\n\" \"$time\" \"$hash\" \"$branch\" \"$message\"; \
done < <(git logx && echo);"'
这适用于Git 1.9a版本。颜色值“auto”显然在这个版本中首次出现。这是一个很好的补充,因为分支名称将获得不同的颜色。例如,这使得区分本地分支和远程分支更加容易。
gitg:基于gtk的存储库查看器。这是新的,但有趣且有用。
我目前正在使用它。
这里是我的社区别名:gitls。使用gitls,您可以查看图形,每次提交只覆盖一行。一切都是彩色的,并带有有用的信息。您还可以检查其他分支上的提交历史记录:
git config --global alias.ls '!f() { git log $1 --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cgreen\\ [%ae,%ar]" --decorate --graph; }; f'
用法:
# shows commits graph on the current branch
git ls
# shows commits graph on the develop branch
git ls develop
以下是图表视图:
虽然我有时使用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等项目解析结果。