[英]Why are my commits via go-git dated 1970?
I am committing changes via 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.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)
}
In my logs, I see this:在我的日志中,我看到了这个:
Date: Thu Jan 1 00:00:00 1970 +0000
Is this expected behavior?这是预期的行为吗? I don't see anyway for me to pass in a date.
反正我不认为我可以通过约会。 A quick inspection of the source shows the Commit object doesn't have any references to date ...
对源代码的快速检查显示 Commit 对象没有任何迄今为止的引用......
Is that right, or am I missing something?是这样,还是我错过了什么?
Pass in the current time to object.Signature
.将当前时间传递给
object.Signature
。 The documentation for object.Signature
shows that you can provide a time.Time
type. object.Signature
的文档显示您可以提供time.Time
类型。 This is also demonstrated in an example on GitHub.这也在 GitHub 上的示例中进行了演示。 Be sure to import
"time"
.一定要导入
"time"
。
_, err = W.Commit("commit message goes here", &git.CommitOptions{
Author: &object.Signature{
Name: username,
Email: email,
When: time.Now(),
},
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.