如何配置git log
以显示提交日期
而非作者日期
?
--pretty
格式之一,例如git log --pretty=fuller
- 这将显示两个日期。如果您只想看到一个日期,但要使其成为提交日期,则可以使用git log --format=<some stuff>
。定义格式的allowable codes中的所有内容都记录在git help log
中。提交日期是%cd
、%cD
、%cr
、%ct
或%ci
之一,具体取决于您喜欢的格式。
如果这是您经常要做的事情,请将其放入别名中或编写辅助脚本以节省输入时间。
%cd
中我们能获取年份和月份吗? - alper--pretty=format
并使用%cr
来获取相对于提交时间的日期。$ git log --graph --pretty=format:'%C(auto)%h%d (%cr) %cn <%ce> %s'
您可以在 git 中定义别名来使其更易使用。我在我的.gitconfig
文件中定义了以下内容:
[alias]
# see `git help log` for detailed help.
# %h: abbreviated commit hash
# %d: ref names, like the --decorate option of git-log(1)
# %cn: commiter name
# %ce: committer email
# %cr: committer date, relative
# %ci: committer date, ISO 8601-like format
# %an: author name
# %ae: author email
# %ar: author date, relative
# %ai: author date, ISO 8601-like format
# %s: subject
# my awesome git log replacement
lol = log --graph --pretty=format:\"%C(auto)%h%d%Creset %C(cyan)(%cr)%Creset %C(green)%cn <%ce>%Creset %s\"
# same as above, but ISO date
lold = log --graph --pretty=format:\"%C(auto)%h%d%Creset %C(cyan)(%ci)%Creset %C(green)%cn <%ce>%Creset %s\"
# using build-in standards
lol2 = log --oneline --graph --decorate
# shows branches and their last commits
lol3 = log --all --graph --decorate --oneline --simplify-by-decoration
在Linux或类似系统中,您可以使用单引号'
代替双引号"
:
[alias]
lol = log --graph --pretty=format:'%C(auto)%h%d%Creset %C(cyan)(%cr)%Creset %C(green)%cn <%ce>%Creset %s'
使用此命令,只需运行git lol
或其他变体即可查看漂亮的输出。
以下是运行git lol --simplify-by-decoration
的输出:
lol
比log
更容易键入,听起来也更好。git log
。以下是在ISO格式中使用日期的git lold
的输出。有助于查看提交的确切日期/时间,并轻松查看贡献者的时区。
编辑2020-06:添加了截屏。使用%C(auto)
(自动/默认着色)替换%h
(提交哈希)和%d
(引用名称)。除电子邮件外,还添加了%cn
(提交者名称)。
git log --graph --pretty=format:\"%C(yellow)%h%Creset%C(cyan)%C(bold)%d%Creset %C(cyan)(%cr)%Creset %C(green)%ce%Creset %s\"
我更喜欢这种格式,不包括作者姓名,包含提交的实际日期。
git log --graph --pretty=format:"%C(yellow)%h%x09%Creset%C(cyan)%C(bold)%ad%Creset %C(green)%Creset %s" --date=short
git log
仅显示提交日期,而不显示其他内容 - Gabriel Staples