在git

时间:2017-04-13 19:16:26

标签: git version-control bitbucket

我有n个存储库,其中这些存储库具有相同的后端但具有不同的前端。我希望能够在提交新更改时传播其他存储库中的新更改。

1 个答案:

答案 0 :(得分:1)

有两种方法可以将更改从repoN提取到其他N-1个存储库(假设更改位于master分支上)。

选项1:子模块

首先,通过git submodule add /path/to/repo1,...,git submodule add /path/to/repoN-1添加其他N-1个存储库作为repoN的子模块。

其次,通过git submodule foreach 'git remote add repoN /path/to/repoN'将repoN添加为这些N-1存储库的另一个远程数据库。

最后,在为repoN提交更改后,您可以执行git submodule foreach 'git fetch repoN && git cherry-pick repoN/master'

选项2:shell脚本

您可以使用shell脚本将更改提取到其他存储库。假设您在repo N中提交更改,现在您可以执行脚本来更新其他N-1存储库(首先,您需要通过git remote add repoN /path/to/repoN为这些n-1存储库添加远程)。该脚本应包含以下函数:

cd /pth/to/repo1
git fetch repoN 
git cherry-pick remoN/master -X theirs

cd /pth/to/repo2
git fetch repoN 
git cherry-pick remoN/master -X theirs
…
cd /pth/to/repoN-1
git fetch repoN
git cherry-pick remoN/master -X theirs