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

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

问题描述

在我的脚本中,我经常使用拥有自己存储库的库(我的或其他人的).我不想在我的 repo 中复制那些,并在每次出现新版本时都坚持更新它们.但是,当有人克隆 repo 时,它应该仍然可以在本地工作并且没有断开的链接.

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?

推荐答案

您可以使用 git 中的子模块执行此操作.在您的存储库中,执行以下操作:

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

git submodule add path_to_repo path_where_you_want_it

因此,如果库的存储库具有 git://github.com/example/some_lib.git 的 URL,并且您希望它位于您的 lib/some_lib项目,你会输入:

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

请注意,这需要从存储库的顶级目录中完成.所以不要cd进入你首先放置它的目录.

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.

当你想更新一个库的更新版本时,cd 进入子模块并拉取:

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

然后,当您执行 git status 时,您应该看到 lib/somelib 列在修改部分中.添加该文件,提交,然后您就是最新的.当协作者将该提交拉入其存储库时,他们会看到 lib/somelib 已修改,直到再次运行 git submodule update.

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天全站免登陆