2

我有两个项目,ProjectAProjectB。他们每个人都有自己的 git repo。这些项目有许多相同的文件。这些文件位于ProjectAProjectB中名为“ 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
...

我在这两个项目上工作。我可能会对ProjectAProjectB上的公共文件进行更改。我希望在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中进行更改并推送它们,我可以轻松地将它们拉入ProjectAProjectB

$ 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 文件?或者也许我做错了什么?

4

1 回答 1

1

而不是使用:

git pull -X subtree

尝试使用subtree pull命令。据说它可以沿着 thesubtree push和其他subtree子命令工作:

git subtree pull --prefix=common common-repo master
于 2014-03-06T02:24:26.780 回答