【问题标题】:Why are my commits via go-git dated 1970?为什么我通过 go-git 提交的日期是 1970 年?
【发布时间】:2020-07-06 16:08:33
【问题描述】:

我正在通过 go-git 提交更改:

import (
  "github.com/tcnksm/go-gitconfig"
  "github.com/walterjwhite/go-application/libraries/logging"

  "gopkg.in/src-d/go-git.v4"
  "gopkg.in/src-d/go-git.v4/plumbing/object"
)

func stackoverflowCommit(R *git.Repository, W *git.Worktree) {
  username, err := gitconfig.Username()
  logging.Panic(err)

  email, err := gitconfig.Email()
  logging.Panic(err)

  _, err = W.Commit("commit message goes here", &git.CommitOptions{Author: &object.Signature{Name: username, Email: email}})

  logging.Panic(err)
}

在我的日志中,我看到了这个:

Date:   Thu Jan 1 00:00:00 1970 +0000

这是预期的行为吗?无论如何,我看不到我可以通过约会。对源代码的快速检查显示 Commit 对象没有任何对日期的引用...

是这样吗,还是我错过了什么?

【问题讨论】:

  • 我没有答案,但 1970 年 1 月 1 日午夜是 Unix time 的零值,这是软件中广泛使用的时间度量。

标签: git go go-git


【解决方案1】:

将当前时间传递给object.SignatureThe documentation for object.Signature 表明您可以提供 time.Time 类型。 这也在 GitHub 上的 an example 中进行了演示。请务必导入"time"

_, err = W.Commit("commit message goes here", &git.CommitOptions{
    Author: &object.Signature{
        Name: username, 
        Email: email, 
        When: time.Now(),
    },
})

【讨论】:

  • 谢谢 - 我会检查我的眼睛。
猜你喜欢
  • 2011-07-02
  • 1970-01-01
  • 2021-11-24
  • 2016-05-07
  • 2017-06-01
  • 2013-05-26
  • 1970-01-01
  • 2014-06-29
相关资源
最近更新 更多