为什么我的go git提交日期是1970年?
我正在通过go git提交更改:为什么我的go git提交日期是1970年?,git,go,go-git,Git,Go,Go Git,我正在通过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
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
这是预期的行为吗?无论如何,我看不出我可以错过一个约会。对源代码的快速检查显示提交对象没有任何对日期的引用
是这样,还是我遗漏了什么?将当前时间传递给
对象。签名
。对于object.Signature
显示您可以提供time.time
类型。
这在GitHub上也有演示。确保导入“时间”
\,err=W.Commit(“这里有提交消息”,&git.CommitOptions{
作者:&object.Signature{
名称:用户名,
电邮:电邮,,
时间:time.Now(),
},
})
我没有答案,但1970年1月1日午夜是零值,这是软件中广泛使用的时间度量。谢谢-我会检查我的眼睛。