git - 为什么我通过1970年的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.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.Signatureobject.SignatureThe 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/

相关文章:

error-handling - Go 中更简洁的错误处理

go - 从返回元组的 func 初始化结构

go - 如何轮询 GitHub 存储库以拉取更改

docker 多阶段构建 Go 镜像 - x509 : certificate signed by unknown authority

go - 删除 go-git 中的本地分支 : branch not found

git - 从私有(private)存储库获取依赖项的正确方法

git - 将一个本地分支 merge 到另一个本地分支

go - 为什么具有匿名结构字段的结构不满足在该类型的别名上定义的方法?

git - 在 git 中转义在文件名中添加前导 "-"?

git - 如何让 CMake 的ExternalProject_Add 在 Visual Studio 中工作(git-submodule 问题)?