如何在 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 git 中的子模块来完成此操作。在您的存储库中,执行以下操作:
因此,如果库的存储库的 URL 为
git://github.com/example/some_lib.git
并且您希望它位于lib/some_lib
在您的项目中,您将输入:请注意,这需要从存储库中的顶级目录完成。因此,不要
cd
进入您首先放置它的目录。添加子模块后,或者每当有人对您的存储库进行全新签出时,您需要执行以下操作:
然后您添加的所有子模块都将以您拥有的同一修订版进行签出。
当您想要更新到某个库的较新版本时,
cd
进入子模块并拉取:然后,当您执行
git status
时,您应该看到lib/somelib
列在修改的部分中。添加该文件并提交,您就已经是最新的了。当协作者将该提交拉入其存储库时,他们会看到lib/somelib
已修改,直到再次运行git submodule update
为止。You can do this with submodules in git. In your repository, do:
So, if the library's repository had a URL of
git://github.com/example/some_lib.git
and you wanted it atlib/some_lib
in your project, you'd enter: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:
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:Then, when you do a
git status
you should seelib/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 seelib/somelib
as modified until they rungit submodule update
again.