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

1
2
3
4
5
6
7
8
9
10
11
12
13
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:

如何确保

这是我的项目结构吗?

1
2
3
4
5
6
7
Project/
|
src/
  |
   github.com/
      |
      packages/

我的GOPATH也指向项目目录

  • 使用标准的go dep工具。不要打架。

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

编辑:从go1.11开始为@jubobs,您可以使用go mod。基本前提与dep

相同

  • 没有提到Go 1.11模块吗?
  • @xReprisal,感谢您的回复,我确实尝试使用dep,但是当我运行dep init " init失败时,出现以下错误:无法确定根项目Project / src的导入路径:dep当前不支持使用GOPATH / src作为项目根目录"
  • @xReprisal,如果我使用dep,那么如果第三方软件包所有者删除该仓库,会发生什么情况。如果要在其他版本中使用我的项目,将如何dep下载该软件包?
  • 我认为dep无法正常工作,因为您在Project内也有项目。 Go对于项目的结构有非常明确的指导。每个项目至少应驻留在Projectsrc文件夹中。
  • 如果您担心软件包被删除,则可以将其下载到$GOPATH,然后通过将其复制到每个项目的内部来手动创建供应商文件夹。尽管我强烈建议不要这样做。