Git 日志> CHANGELOG.md 产生奇怪的字符



我使用以下命令在提交之前立即生成 CHANGELOG.md:

git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an <%ae> %Cgreen%d %Creset%s' --date=short --graph > CHANGELOG.md

当我直接运行命令而不是> CHANGELOG.md 时,我得到了预期的漂亮输出:

|
| * 97997cf 6 days ago Timothy Stephens <timothy.f.stephens@gmail.com>  bugzid:16451 new lockfile
* | 4245715 6 days ago Timothy Stephens <timothy.f.stephens@gmail.com>  bugzid:16451 added tag script v1, new lockfile
|/
* 98cc3a6 6 days ago Timothy Stephens <timothy.f.stephens@gmail.com>  bugzid:16451 include .lock for deploy, temporarily remove tests automatically running
* eaa8b2f 6 days ago Timothy Stephens <timothy.f.stephens@gmail.com>  bugzid:16451 removed submodulegit status
* 3b6c82f 6 days ago Timothy Stephens <timothy.f.stephens@gmail.com>  bugzid:16451 merge master 2014-11-13

但在 CHANGLOG.md 中,我得到了奇怪的^[[34m字符:

|
| * ^[[33m97997cf ^[[31m6 days ago ^[[34mTimothy Stephens <timothy.f.stephens@gmail.com> ^[[32m ^[[mbugzid:16451 new lockfile
* | ^[[33m4245715 ^[[31m6 days ago ^[[34mTimothy Stephens <timothy.f.stephens@gmail.com> ^[[32m ^[[mbugzid:16451 added tag script v1, new lockfile
|/
* ^[[33m98cc3a6 ^[[31m6 days ago ^[[34mTimothy Stephens <timothy.f.stephens@gmail.com> ^[[32m ^[[mbugzid:16451 include .lock for deploy, temporarily remov$
* ^[[33meaa8b2f ^[[31m6 days ago ^[[34mTimothy Stephens <timothy.f.stephens@gmail.com> ^[[32m ^[[mbugzid:16451 removed submodulegit status
* ^[[33m3b6c82f ^[[31m6 days ago ^[[34mTimothy Stephens <timothy.f.stephens@gmail.com> ^[[32m ^[[mbugzid:16451 merge master 2014-11-13

这些是用于在控制台中显示颜色的转义字符:http://misc.flogisoft.com/bash/tip_colors_and_formatting。

当您

将输出重定向到 CHANGELOG.md 时,您应该让 git-log 不显示颜色

最新更新