Should go.sum file be checked in to the git repository?

I have a program with source code hosted on GitHub that uses Go Modules introduced in go 1.11.

go.mod file describes my dependencies, but go.sum file seems to be a lockfile. Should I be adding go.sum to my repository or should I gitignore it?

42998 次浏览

(建立在 上一个答案上)

是的,提交 go.sum

确保您的 go.sum文件与 go.mod文件一起提交。请参阅下面的常见问题以了解更多细节和理由。

来自 常见问题:

我应该提交‘ go.sum’文件和‘ go.mod’文件吗?

通常模块的 go.sum文件应该与 你的 go.mod文件。

  • go.sum包含特定模块版本内容的预期加密校验和。
  • 如果有人克隆了您的存储库并使用 go 命令下载了您的依赖项,那么如果有任何错误,他们将收到一个错误 它们下载的依赖项副本与 在你的 go.sum中对应的条目。
  • 此外,go mod verify检查模块下载的磁盘上缓存副本是否仍然与 go.sum中的条目匹配。
  • 注意,go.sum不是一些替代依赖管理系统中使用的锁文件(go.mod提供了足够的信息) 可重复建造)。
  • See very brief 理由 from 关于为什么你应该检查你的 go.sum ”模组下载及 核实” section of the tip documentation for more details. See possible future 正在讨论的扩展,例如 # 24117 # 25530.