doudouba4520 2016-05-08 22:57
浏览 196
已采纳

去获取,Git和依赖

I'm a moderately experienced Go developer and Git user, but there's something that I can't seem to wrap my head around.

Usually my team uses .gitmodules for package dependencies, and that has been a successful pattern because it points to an exact commit. 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. 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.

Usually I would say "oh, you forgot to run git submodule update --init", but of course they're not submodules. 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.

My real question here is: what actually happens when I go get a package and then commit it to my repository? 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?

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?

  • 写回答

1条回答 默认 最新

  • duanlang0025 2016-05-08 23:48
    关注

    Basically go get downloads and installs a project. It starts by cloning the repository of the project you want into the 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). 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. 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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器