我正在用 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/