原始.gitmodules
文件使用了硬编码的https
url,但是对于某些自动测试,我从中ssh
进行了克隆,并使子模块url相对于../ModuleName
。我也不想将这些更改推回存储库中。
# change the https://github.com/ with [email protected]:
sed -i 's/https:\/\/github.com\//[email protected]:/g' ".git/config"
# delete the url lines from the submodule blocks of .git/config
sed -i '/submodule/ {$!N;d;}' ".git/config"
# change hardcoded https:// urls of submodules to relative ones
sed -i 's/https:\/\/github.com\/ProjName/../g' ".gitmodules"
# also make the same change in the .git/modules/*/config
sed -i 's/https:\/\/github.com\/ProjName/../g' .git/modules/*/config
# sync and update
git submodule sync
git submodule update --init --recursive --remote
上面的代码段可以满足我的要求。但是,令人讨厌的是,.git/modules/
文件夹似乎不受版本控制,但是如果我删除它,git submodule sync
大多数其他Git操作就会停止工作。
.git/modules
修改.gitmodules
和.git/config
文件后,是否有办法重新生成?
如果只想修改用于本地存储库的子模块的URL,则不要修改.gitmodules
文件,仅用于要推送的更改。
相反,首先初始化本地子模块配置:
git submodule init
然后修改.git/config
文件以照常更改子模块URL。(再次,无需在.gitmodules
此处进行修改,如果这是一个新的克隆,您可能还.git/modules
没有。)
正如@jthill指出的那样,修改子模块URL的更简单方法是:
git config submodule.moduleName.url ssh://user@server/path
在这一点上,你不希望运行git submodule sync
,因为这将覆盖您刚刚从价值观所做的更改.gitmodules
文件。而是直接转到:
git submodule update --recursive --remote
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句