为什么我通过 go-git 提交的日期是 1970 年?
Why are my commits via go-git dated 1970?
我正在通过 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 WhosebugCommit(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 对象没有任何日期引用...
是这样吗,还是我漏掉了什么?
将当前时间传给object.Signature
。 The 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(),
},
})
我正在通过 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 WhosebugCommit(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 对象没有任何日期引用...
是这样吗,还是我漏掉了什么?
将当前时间传给object.Signature
。 The 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(),
},
})