我想在路径中添加一个带有变量的子模块,以便每个人都可以使用相同的 .gitmodules。
即...git submodule add $USER/pub/repo.git我不希望 $USER 在 .gitmodules 内扩展。我尝试过git submodule add '$USER/pub/repo.git',但找不到存储库。当尝试使用环境变量添加远程时,我看到了相同的行为。
这是不可能的,因为git不会扩展 URL 中的环境变量。
要执行您想要的操作,请使用git config --global url.<base>.insteadOf动态替换 URL。团队中的每个人都必须设置 URL 替换:
git config --global url.<new-url>.insteadOf <old-url>
Run Code Online (Sandbox Code Playgroud)
请参阅https://stackoverflow.com/search?q=%5Bgit-submodules%5D+insteadof中的更多示例