git - 我应该提交 Godeps/_workspace 还是 Godeps.json 就足够了?

标签 git heroku go dependencies

我正在用 Go 编写一个项目以部署在 heroku 上,使用 godep 管理依赖项.

当我 godep save 时,我得到一个 Godeps.json 文件,其中列出了我的依赖项和版本,以及一个 _workspace/ 目录和源对于复制的所有依赖项。我宁愿不提交 _workspace,所有这些代码已经在 github 上的其他地方。似乎 Godeps.json 包含了我们在 heroku buildpack 时 go get 版本锁定依赖项所需的所有信息。

Several sources建议提交完整的 Godeps/ 目录,但其他人建议这样做 might not be necessary .

godep 文档没有多大帮助:

This will save a list of dependencies to the file Godeps/Godeps.json, and copy their source code into Godeps/_workspace. Read over its contents and make sure it looks reasonable. Then commit the file to version control.

是 Godeps.json 文件吗?

最佳答案

官方回答:

来自 GitHub 问题 #131 :

The intended use of godep is to vendor dependencies and commit the _workspace directory to version control. See the proposal document by @kr linked in #123 (proposal: http://goo.gl/RpYs8e) As discussed in that proposal, godep used to have a mode (-copy=false) that supported not vendoring the dependencies. My guess is that the ambiguous language in the Readme may be due to that. This mode has been removed as documented in #123.

这里还有 godep 作者在谈论他的项目和背后的想法 - Vendoring and Import Path Rewriting

个人意见:

我认为没有正确的方法。

提交 vendor 库确实看起来很尴尬,但它有它的优势:

  • 您不依赖外部服务(GitHub 等)。 GitHub 出现故障,也许你有一些糟糕的公司政策阻止你使用它,也许存储库消失了或者它的历史被重写了,也许你在防火墙后面(暂存/构建服务器)等等。
  • 每次对您的部门进行更新时,您都会很好地了解更改的内容。 这有助于更新到新版本,或者如果您筛选正在使用的代码,则只需跟踪更改。

最后由你来权衡利弊。就个人而言,每次我必须提交 vendor 代码时我都会畏缩,但在我的 Go 项目中我会这样做。至少现在是这样。

此外,Google 和 Facebook 等公司大多将所有内容保存在一个存储库中,其中包括 vendor 代码(或者我听说过)。

关于该主题的有趣文章: Go Package Management

关于git - 我应该提交 Godeps/_workspace 还是 Godeps.json 就足够了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26334220/

相关文章:

git - 哪些名称是有效的 git 标签?

node.js - 错误: Cannot find module './formats' when deploying node app on heroku server

google-app-engine - AWS、DigitalOcean 与 heroku、谷歌应用引擎

json - Golang 结构字段名称并解码到此结构中

bash - 如何仅获取要在预提交 Hook 中处理的文件的更改部分?

git - 如何将这个修改后的文件推送到github存储库

Git: stash/删除永远不会被版本化的文件

ruby-on-rails - PostgreSQL安装报错--无法分配内存

string - 将字符串与指向字符串的指针作为函数的参数传递时,时间复杂度有何不同?

go mod 校验和不匹配