【问题标题】:Version control third party packages in golanggolang 中的版本控制第三方包
【发布时间】:2019-03-25 08:28:41
【问题描述】:

我在 golang 中使用第三方包,我想将它们添加到我的 git 存储库中,当我输入命令 git add . 时,它给了我以下错误

warning: adding embedded git repository: github.com/beorn7/perks
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint: 
hint:   git submodule add <url> github.com/beorn7/perks
hint: 
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint: 
hint:   git rm --cached github.com/beorn7/perks
hint: 

如何确保我对软件包进行了正确的版本控制以及我是否以正确的方式对我的第三方软件包进行版本控制?

这是我的项目结构

Project/
|
src/
  |
   github.com/
      |
      packages/

我的 GOPATH 也指向项目目录

【问题讨论】:

  • 使用标准的go dep 工具。不要与工具作斗争。

标签: git go


【解决方案1】:

据我了解,您没有使用任何包管理器,而是将包导入您的 $GOPATH。我建议您使用像 dep 这样的包管理器,它构建包含所有依赖项的 vendor 目录。当你运行dep ensure 时,它会自动检查你的代码并自动拉取所有依赖项。

编辑: 作为自 go1.11 以来的@jubobs,您可以使用go mod。基本前提同dep

【讨论】:

  • 没有提到 Go 1.11 模块?
  • @xReprisal,感谢您的回复,我确实尝试使用 dep,但是当我运行 dep init "init failed: 无法确定根项目 Project/src 的导入路径时出现以下错误: dep 目前不支持使用 GOPATH/src 作为项目根目录"
  • @xReprisal,如果我使用 dep 以及如果第三方包所有者删除 repo 会发生什么。如果我想在另一个版本中使用我的项目,dep 将如何下载包?
  • 我认为 dep 不起作用,因为您的项目位于 Project/ 中,这也是 $GOPATH。 Go 对如何构建项目有非常明确的指导方针。每个项目至少应该位于Project/src 文件夹中。
  • 如果您害怕软件包被删除,那么您可以将它们下载到您的$GOPATH,然后通过将它们复制到您的每个项目中来手动创建供应商文件夹。虽然我强烈建议不要这样做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-09-22
  • 2018-08-08
  • 1970-01-01
  • 2014-10-17
  • 1970-01-01
相关资源
最近更新 更多