我正在通過 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 對象沒有任何對日期的引用...是這樣嗎,還是我錯過了什么?
1 回答

撒科打諢
TA貢獻1934條經驗 獲得超2個贊
將當前時間傳遞給object.Signature。的文檔顯示object.Signature您可以提供time.Time類型。這也在GitHub 上的示例中得到了演示。一定要導入"time"。
_, err = W.Commit("commit message goes here", &git.CommitOptions{
Author: &object.Signature{
Name: username,
Email: email,
When: time.Now(),
},
})
- 1 回答
- 0 關注
- 172 瀏覽
添加回答
舉報
0/150
提交
取消