我如何在git repo中链接依赖关系? [英] How can I have linked dependencies in a git repo?

查看:243
本文介绍了我如何在git repo中链接依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的脚本中,我经常使用有自己的回录的图书馆(我或其他人)。我不想在我的回购中复制这些,并且每次出现新版本时都会更新它们。
然而,当有人克隆回购时,它仍然应该在本地工作,而不是断开链接。



有什么想法可以做什么?

解决方案

您可以使用git中的子模块来执行此操作。在您的资料库中,执行以下操作:

  git submodule add path_to_repo path_where_you_want_it 

所以,如果图书馆的资料库的URL为 git://github.com/example/some_lib.git 您希望在项目中的 lib / some_lib 中输入:

  git submodule add git://github.com/example/some_lib.git lib / some_lib 

请注意,这需要从存储库中的顶级目录中完成。所以不要将 cd 插入到您首先放在的目录中。



添加子模块后,或者每当有人对您的存储库进行新的检出时,您需要执行以下操作:

  git子模块init 
git子模块更新

然后,您添加的所有子模块将在相同的修订版本中检出。



当您想更新到其中一个库的更新版本, cd 到子模块并拉:

  cd lib / some_lib 
git pull

然后,当您执行 git status 时,您应该会看到 lib / somelib 在修改部分中列出。添加该文件,提交,并且您是最新的。当协作者将这个提交提交到他们的存储库中时,他们会看到 lib / somelib 被修改,直到它们运行 git子模块更新再次。


In my scripts, I often use libraries (mine or others') that have their own repos. I don't want to duplicate those in my repo and get stuck with updating them every time a new version comes out. However, when somebody clones the repo, it should still work locally and not have broken links.

Any ideas about what I could do?

解决方案

You can do this with submodules in git. In your repository, do:

git submodule add path_to_repo path_where_you_want_it

So, if the library's repository had a URL of git://github.com/example/some_lib.git and you wanted it at lib/some_lib in your project, you'd enter:

git submodule add git://github.com/example/some_lib.git lib/some_lib

Note that this needs to be done from the top-level directory in your repository. So don't cd into the directory where you're putting it first.

After you add a submodule, or whenever someone does a fresh checkout of your repository, you'll need to do:

git submodule init
git submodule update

And then all submodules you've added will be checked out at the same revision you have.

When you want to update to a newer version of one of the libraries, cd into the submodule and pull:

cd lib/some_lib
git pull

Then, when you do a git status you should see lib/somelib listed in the modified section. Add that file, commit, and you're up to date. When a collaborator pulls that commit into their repository, they'll see lib/somelib as modified until they run git submodule update again.

这篇关于我如何在git repo中链接依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆