如何 git 合并分叉

how to git merge a fork

我有一个 git 源代码存储库,其结构类似于这样。

origin/master
    root\
    +--src\
       +--A\
       +--B\
       +--C\

upstream/master
    src\
    +--A\
    +--B\
    +--C\

我对 src/ 进行了局部修改,src/ 的所有者对 upstream/master 进行了其他更改。我想用他们的 src/ 更新我的本地分支。

我想做一个 git merge upstream/master 详细 here。但这给我留下了这样的结构:

origin/master
root\
+--src\
|  +--A\
|  +--B\
|  +--C\
+--A\
+--B\
+--C\

所以,我找到了 Subtree Merging,但我收到有关文件重叠的错误。 (当然他们重叠了!我正在合并!)

E:\root>git status
On branch master
nothing to commit, working directory clean

E:\root>git read-tree --prefix src/ -u upstream/master
error: Entry 'src/.gitattributes' overlaps with 'src/.gitattributes'.  Cannot bind.

我需要做什么才能将上游存储库与我的复刻合并?

来自 Git read-tree 文档:

Keep the current index contents, and read the contents of the named tree-ish under the directory at <prefix>. The command will refuse to overwrite entries that already existed in the original index file. Note that the <prefix>/ value must end with a slash.

read-tree基本上不做合并。你需要做一个合并。试试看:

git merge upstream/master -s recursive -X subtree=src/