我有两个项目,ProjectA和ProjectB。他们每个人都有自己的 git repo。这些项目有许多相同的文件。这些文件位于ProjectA和ProjectB中名为“ common ”的文件夹中。这是文件示例:
项目A:
...
cat-folder
dog-folder
common
commonFile1
commonFile2
fish-file.php
squirrel-file.txt
...
项目B:
...
potato-folder
apple-folder
common
commonFile1
commonFile2
tomato-file.xml
pineapple-file.csv
...
我在这两个项目上工作。我可能会对ProjectA或ProjectB上的公共文件进行更改。我希望在ProjectA中所做的公共文件的更改也出现在ProjectB的公共文件中(反之亦然)。因此,我希望两个项目中的“ common ”文件夹始终保持最新并包含相同的文件。
为此,我使用git subtree。我创建了第三个仓库“ common-repo ”,将“ common ”文件夹的所有文件放在那里,然后从两个项目中删除“ common ”文件夹。然后在每个项目中我都会这样做:
$ cd /path/to/ProjectA # or ProjectB
$ git remote add common-repo https://my_user@bitbucket.org/url/of/common-repo
$ git fetch common-repo
$ git subtree add --prefix=common/ common-repo master --squash # this command adds the "common" folder with my common files to the current project
然后,如果我在common-repo中进行更改并推送它们,我可以轻松地将它们拉入ProjectA或ProjectB:
$ cd /path/to/ProjectA # or ProjectB
$ git pull -X subtree=common common-repo master # this pulls changes from common-repo
但是,当我更改在ProjectA(或ProjectB )中工作的“ common ”文件夹中的文件并尝试将其推送到common-repo时,就会出现问题。
$ cd /path/to/ProjectA # or ProjectB
$ git subtree push --prefix=common common-repo master # !!!!
最后一个命令将ProjectA的所有文件推送到common-repo,包括它的非公共文件!
如何推送到“ common ”文件夹的common-repo only 文件?或者也许我做错了什么?