git log format打印空日期

时间:2013-10-16 15:15:53

标签: git

我有一个git存储库,其中所有提交都是使用Python脚本和dulwich库按计划执行的。

我正在尝试使用自定义格式的git log打印提交列表及其提交日期,但我找不到可用的格式字符串。

这是我在运行git log --format=raw时获得的一次提交:

commit d955a72160fdacfc7c22eccdccaf8b343c882ebb
tree d6b8baffb86d16b90552250da7bfe39828d16982
parent 03bccd572a8ed7e04c96bf27a010d7ef39165e1c
author auto.py 1381493109 +0000
committer auto.py 1381493109 +0000

    commit message

将其与实际git工具创建所有提交的repo进行比较,同时使用--format=raw

commit 72dbd4358c8685cfd604b4146c7728c82999a97e
tree cfc5254c5f96b50ec6b5abf1b573e97989a52b19
parent 2f2a87f7f1e87afe1b93d659e4cd435532352ada
author me <me@example.com> 1381503599 -0300
committer me <me@example.com> 1381503599 -0300

    commit message

使用git log --format文档,我构建了一个格式字符串,该字符串应该显示作者和&amp;以每种格式提交日期,两侧都包含提交哈希。然后我在德威管理的仓库上运行它:

$ git log --format="format:%h %an %ad %aD %ar %at %ai %cn %cd %cD %ar %at %ai %h"
d955a72             d955a72

对于git-managed repo:

$ git log --format="format:%h %an %ad %aD %ar %at %ai %cn %cd %cD %ar %at %ai %h"
72dbd43 me Fri Oct 11 11:59:59 2013 -0300 Fri, 11 Oct 2013 11:59:59 -0300 5 days ago 1381503599 2013-10-11 11:59:59 -0300 mRB0 Fri Oct 11 11:59:59 2013 -0300 Fri, 11 Oct 2013 11:59:59 -0300 5 days ago 1381503599 2013-10-11 11:59:59 -0300 72dbd43

每个日期都是空字符串。我想dulwich以不同的方式存储提交日期,但我找不到任何方式以格式字符串访问它们。

我可以使用git log访问dulwich提交中的时间戳的自定义格式吗?

我使用的是git版本1.8.3.4(Apple Git-47)。

2 个答案:

答案 0 :(得分:1)

我认为dulwich创建的提交无效,因为作者和提交者的电子邮件地址在Git中始终是必需的(解析器正在寻找封闭的<>)。解析 author / committer ident 失败导致无法解析时间戳。

答案 1 :(得分:0)

Antoine Pelisse的回答是正确的:我的提交在他们的作者/提交者记录中没有电子邮件地址,因此它们无效并且git无法解析它们的格式。

我能够通过在工作目录中执行以下过滤器来修复我的存储库。请注意,这将无条件地更新所有提交作者:

git filter-branch --env-filter "
GIT_AUTHOR_EMAIL='foo@bar.com'
GIT_COMMITTER_EMAIL='foo@bar.com'
GIT_AUTHOR_NAME='auto.py'
GIT_COMMITTER_NAME='auto.py'
"

幸运的是,git维护作者并在上述过滤器中提交日期。 (在git版本1.7.2.5和git版本1.8.3.4(Apple Git-47)上验证)

为了避免将来提交中出现问题,我在通过dulwich进行了以下更改:

# old: do not use
# repo.do_commit("message", committer="auto.py")

# fixed
repo.do_commit("message", committer="auto.py <foo@bar.com>")

完成上述操作后,我的git log格式字符串正常工作。

相关问题