使git commit在子模块中对其他本地仓库可用



我有一个由其他几个存储库使用的子模块,我正在对子模块中的代码进行更改,并且我想在我将子模块更改推送到远程之前,使我的更改可用于我的其他两个本地存储库。我的想法是,我希望能够先测试其他两个仓库的代码,然后再推送它们之间共享的代码。

如果我只是在子模块做一个本地提交,我怎么能使我的其他本地仓库可用的变化?这可能吗?似乎应该是这样,因为我所要做的就是让本地代码对本地代码可用。

当然可以。如果您在两个本地文件夹中有相同的子模块,您可以在有更改的文件夹中添加新的remote,设置为另一个repo的路径。假设你有一个这样的tree:

├── git_local
│   ├── b
│   └── git_submod
│       └── a
├── git_submod
│   └── a
└── second_local
├── c
└── git_submod
└── a

其中git_localsecond_local包含git_submod作为子模块。目前,您已经更新了git_local中的子模块,但您想要"推送"。second_local内部的子模块中的这些更改。添加一个remote:

cd git_local/git_submod
git remote add testing_remote ../../second_local/git_submod/
git push testing_remote master

并且其他本地回购也被更新了。考虑到您必须更改denyCurrentBranch的默认配置,以便将其推送到非裸repo。

这里是second_local/git_submod中要运行的命令:

git config receive.denyCurrentBranch "updateInstead"

最新更新