Jes*_*sen 27 git formatting logging
我真的很喜欢简短的git日志格式,我可以看到作者,日期和更改说明,如下所示:
git log --pretty=format:"%h%x09%an%x09%ad%x09%s"
Run Code Online (Sandbox Code Playgroud)
哪个输出:
fbc3503 mads Thu Dec 4 07:43:27 2008 +0000 show mobile if phone is null...
ec36490 jesper Wed Nov 26 05:41:37 2008 +0000 Cleanup after [942]: Using timezon
ae62afd tobias Tue Nov 25 21:42:55 2008 +0000 Fixed #67 by adding time zone supp
164be7e mads Tue Nov 25 19:56:43 2008 +0000 fixed tests, and a 'unending appoi
Run Code Online (Sandbox Code Playgroud)
(来自stackoverflow问题" 链接文本 ")
现在,问题是,如何将其保存为我的机器上的新格式,因此我只需编写类似的内容,例如:
git log --format=jespers_favourite
Run Code Online (Sandbox Code Playgroud)
tdb*_*bit 34
Git中的新版本(带v1.7.8确认),可以设置一个名为漂亮地打印日志格式使用git config pretty.named_format.这些可在被设定机宽,用户或文件级别与<file-option>参数.
创建一个名为jespers_favourite或整个机器使用的日志格式--system
git config --system pretty.jespers_favourite "%h%x09%an%x09%ad%x09%s"
Run Code Online (Sandbox Code Playgroud)
对于单个用户使用'--global'
git config --global pretty.jespers_favourite "%h%x09%an%x09%ad%x09%s"
Run Code Online (Sandbox Code Playgroud)
除非另外定义,否则<file-option>将参数保留为空白将默认设置当前存储库的配置文件.git/config.
Von*_*onC 21
考虑到git log手册页提到:
--pretty[=<format>]
--format[=<format>]
Run Code Online (Sandbox Code Playgroud)
以给定格式打印提交日志的内容,其中可以是oneline,short,medium,full,fulller,email,raw和format之一:省略时,格式默认为中.
在<format>只能有预定义值.
这只会让您可以将别名定义为该命令的快捷方式.
[alias]
jespers_favourite = log --pretty=format:"%h%x09%an%x09%ad%x09%s"
Run Code Online (Sandbox Code Playgroud)
要么
[alias]
compactlog = log --pretty=format:"%h%x09%an%x09%ad%x09%s"
Run Code Online (Sandbox Code Playgroud)
dla*_*lin 10
使用最新版本的 git(此处为 1.7\xe2\x80\xa6 2.21),您可以将默认格式更改为命名格式或格式字符串。当您这样做时,您也可以添加一些漂亮的格式自动颜色。我还发现编辑文件比使用命令更容易;但我首先从它们开始获得正确的配置文件格式,然后进行修补。
\ngit config --global --add format.pretty \\\n"%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s"\nRun Code Online (Sandbox Code Playgroud)\n结果添加到您.gitconfig的:
[format]\n pretty = %C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s\nRun Code Online (Sandbox Code Playgroud)\n但是,如问题后面部分所述,添加命名格式可能对您更有用。
\n[format]\n pretty = %C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s\nRun Code Online (Sandbox Code Playgroud)\n或者添加到您的.gitconfigas:
[pretty]\n dateline = format:%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s\nRun Code Online (Sandbox Code Playgroud)\n如果你添加两者,你可以让他们读:
\n[pretty]\n dateline = format:%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s\n\n[format]\n pretty = dateline\nRun Code Online (Sandbox Code Playgroud)\nformat:应该注意前缀的差异,我个人喜欢将默认的漂亮格式保留为medium. 如您所知,该%ad部分可以通过, , , , , , ;--date=relative或其中任何一个进行修改;所以我喜欢这样使用它:defaultiso8601localrawrelativerfc2822short
git config --global pretty.dateline \\\n"format:%C(yellow)%h%Creset%x09%Cred%<(13)%an%Creset%x09%Cblue%ad%Creset%x09%s"\nRun Code Online (Sandbox Code Playgroud)\n
小智 6
您可以使用 git-config 配置默认的漂亮格式。来自 git-config 文档:
format.pretty
The default pretty format for log/show/whatchanged command, See git-log(1), git-show(1), git-whatchanged(1).
Run Code Online (Sandbox Code Playgroud)
例如:
git config --add format.pretty fuller
或原始海报所需的格式:
git config --add format.pretty "%h%x09%an%x09%ad%x09%s"
与其他 git 配置设置一样,format.pretty 可以在全局、系统或存储库范围(默认)设置。
| 归档时间: |
|
| 查看次数: |
12326 次 |
| 最近记录: |