繁体   English   中英

如何配置“git log”以显示“提交日期”

[英]How to configure 'git log' to show 'commit date'

如何配置git log以显示commit date而不是author date

有几个选项可以漂亮地打印日期。 可能最简单的方法是使用一种预烘焙的--pretty格式,例如git log --pretty=fuller - 这将显示两个日期。 如果您只想查看一个日期,但将其设为提交日期,则可以使用git log --format=<some stuff> 用于定义格式的所有允许代码都记录在git help log 提交日期是%cd%cD%cr%ct%ci ,具体取决于您喜欢的格式。

如果这是您想要经常做的事情,请将其放在别名中或编写辅助脚本以节省打字时间。

您可以使用--pretty=format并使用%cr对于提交日期。

例如:

$ git log --graph --pretty=format:'%C(auto)%h%d (%cr) %cn <%ce> %s'

您可以在 git 中定义别名以使其更易于使用。 我的.gitconfig有以下.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的输出:

git 大声笑输出

  • 看起来不错。 :)
  • lollog更容易输入,而且听起来也更好。
    • 如果您需要,还可以让您访问常规的git log
  • 您的眼睛可以通过不同的颜色快速浏览内容。
  • 姓名和电子邮件对于有许多贡献者的大型项目/组织非常有用。
  • 对 hash/ref 使用默认着色,因为它已经很不错了。

这是带有 ISO 格式日期的git lold输出。 查看提交的确切日期/时间很有用,并且能够轻松查看贡献者的时区。

在此处输入图片说明

编辑 2020-06 :添加了屏幕截图。 更新为对%h (提交哈希)和%d (引用名称)使用%C(auto) (自动/默认着色)。 除了电子邮件之外,还添加了%cn (提交者名称)。

我更喜欢这种格式,不包括作者姓名,但包括实际提交日期。

git log --graph --pretty=format:"%C(yellow)%h%x09%Creset%C(cyan)%C(bold)%ad%Creset  %C(green)%Creset %s" --date=short

可能对某人有用。 我正在寻找带有作者姓名的日期和时间戳。

在此处输入图片说明

git log --graph --pretty=format:"%C(yellow)%h%x09%Creset%C(cyan)%C(bold)%ad%Creset %C(yellow)%cn%Creset  %C(green)%Creset %s" --date=default

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM