我通过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对象迄今没有任何引用...
是这样吗,还是我想念什么?
最佳答案
将当前时间传递给object.Signature
。 object.Signature
的The documentation表明您可以提供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(),
},
})
关于git - 为什么我通过1970年的go-git提交内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60860256/