简体   繁体   English

去获取,Git和依赖

[英]Go Get, Git and Dependencies

I'm a moderately experienced Go developer and Git user, but there's something that I can't seem to wrap my head around. 我是一位经验丰富的Go开发人员和Git用户,但是有些事情似乎无法解决。

Usually my team uses .gitmodules for package dependencies, and that has been a successful pattern because it points to an exact commit. 通常,我的团队将.gitmodules用于程序包依赖关系,这是一个成功的模式,因为它指向确切的提交。 The entire "vendoring problem" has been solved for us in this way. 这样就为我们解决了整个“供应商问题”。

However, I recently created a project and used go get to fetch various packages from GitHub instead of using git submodule add . 但是,我最近创建了一个项目,并使用go get从GitHub提取了各种软件包,而不是使用git submodule add I finished the project, committed everything to my git repo, but when a teammate cloned out the repo, the source code for the dependencies was missing. 我完成了项目,将所有内容都提交给git repo,但是当队友克隆出repo时,缺少了依赖项的源代码。

Usually I would say "oh, you forgot to run git submodule update --init ", but of course they're not submodules. 通常我会说“哦,您忘记了运行git submodule update --init ”,但是它们当然不是子模块。 So...I could tell him to run go get -u or something (right?) but that means I'm at the mercy of the dependency's master branch--enter vendoring. 所以...我可以告诉他go get -u或其他东西(对吗?),但这意味着我受依赖项的master分支的支配-输入供应商。

My real question here is: what actually happens when I go get a package and then commit it to my repository? 我在这里真正的问题是:当我到底发生了什么go get包,然后将其提交到我的仓库? It's not committed into my source tree, and it's not a submodule...I can't tell what the heck it is! 它没有提交到我的源代码树中,也不是子模块...我无法分辨它到底是什么! What is the precise way that go get and Git are behaving and interacting here? go get和Git在这里表现和交互的确切方法是什么?

Bonus round: Why would you want this behavior? 奖励回合:您为什么要这种行为? Under what circumstances would you want to commit another project into your repo in a way that forces new checkouts to pull the latest version of the source every time? 在什么情况下,您想以强制新签出每次拉取源的最新版本的方式将另一个项目提交到您的仓库中?

Basically go get downloads and installs a project. 基本上go get下载并安装一个项目。 It starts by cloning the repository of the project you want into the GOPATH. 首先将所需项目的存储库克隆到GOPATH中。 So 所以

go get github.com/foo/bar

would be equal to 等于

cd $GOPATH/src/github.com/foo
git clone git@github.com:foo/bar.git

which is a repository of its own. 这是它自己的存储库。

As of go 1.5 the "vendoring problem" has been solved in a very neat and elegant way and as of go 1.6 it's become the standard way (it was only an experinemt in 1.5). 从1.5版开始,“供应商问题”已经以一种非常简洁的方式解决了,从1.6版开始,它已成为标准方式(在1.5版中只是一种实验)。 This way you only add the (sub) packages (sometimes single files) you really need, to the structure / repository of your project. 这样,您只需将真正需要的(子)包(有时是单个文件)添加到项目的结构/存储库中。 There are a few tools out there that take care of vendoring, including godep , from which we currently switched to govendor . 那里有一些用于管理供应商的工具,包括godep ,目前我们govendor切换到govendor It has pretty awesome features. 它具有很棒的功能。 One of which is to update the dependency in your project to a given state (commit, tag, etc) but you can still have the package for other projects, you're working on. 其中之一是将项目中的依赖项更新为给定状态(提交,标记等),但是您仍可以使用正在处理的其他项目的程序包。
Regarding the bonus question... I'm affraid I'm a bit confused and affraid I don't understand the question in it completely, I'd love to answer it though. 关于奖金问题...我很困惑,我有点困惑,我无法完全理解其中的问题,不过我很想回答。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM