如何将git子模块更改为指向子文件夹? [英] How to change a git submodule to point to a subfolder?

查看:1138
本文介绍了如何将git子模块更改为指向子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

浏览 SubModule教程,我从博托项目。然后,我发现我实际上只需要这个项目的一个子集 - 特别是 boto 文件夹。 / p>

我想将我的子模块更改为指向此文件夹。当我查看.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作业:


  1. git fetch 将该存储库转换为目录

  2. 使用 git filter-branch 更新子目录位于顶层的分支。

  3. 将存储库的该分支添加为子模块。但是,这一切都有点烦琐,我的偏好只是将整个存储库作为一个子模块。


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:

  1. git fetch that repository into a directory
  2. Use git filter-branch to update a branch where the subdirectory is at the top level.
  3. 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屋!

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