如何将git子模块更改为指向子文件夹? [英] How to change a git submodule to point to a subfolder?
问题描述
我想将我的子模块更改为指向此文件夹。当我查看.gitmodules时,我看到
$ p $ [submodulebackup / src / boto]
path = backup / src / boto
url = https://github.com/boto/boto.git
我应该使用哪个网址而不是 https://github.com/boto/boto.git ?在我更改URL后,是否应该在本地删除boto文件夹并重新进行拔取?
解决方案子模块总是指向存储库 - 不能指定只需要存储库的子文件夹,就像git不支持狭义克隆一样。
如果您无法将整个存储库作为子模块来运行,那么您可以始终创建一个从boto克隆的新存储库,然后设置一个cron作业:
-
git fetch
将该存储库转换为目录 - 使用
git filter-branch
更新子目录位于顶层的分支。 - 将存储库的该分支添加为子模块。但是,这一切都有点烦琐,我的偏好只是将整个存储库作为一个子模块。
Skimming through the SubModule tutorial, I created a submodule out of the boto project. Then, I discovered that I actually need only a subset of this project - specifically, the boto folder.
I would like to change my submodule to point to this folder. When I look in .gitmodules, I see
[submodule "backup/src/boto"]
path = backup/src/boto
url = https://github.com/boto/boto.git
What URL should I use instead of https://github.com/boto/boto.git? After I change the URL, should I delete the boto folder locally and re-pull?
I'm afraid the URL for submodules always just points to the repository - you can't specify that you only want a subfolder of a repository, in the same way that git doesn't support "narrow clones" in general.
If you can't live with having the whole repository as a submodule, you could always create a new repository that's cloned from boto and then set up a cron job to:
git fetch
that repository into a directory- Use
git filter-branch
to update a branch where the subdirectory is at the top level. - Add that branch of the repository as the submodule. However, that's all a bit fiddly and my preference would just be to live with having the whole repository as a submodule.
这篇关于如何将git子模块更改为指向子文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!