将一个git存储库移至另一个时如何解决冲突

时间:2019-10-06 13:05:04

标签: git repository git-merge

我有两个存储库repo-A和repo-B。我想将repo-A移到repo-B作为子文件夹。我的问题与可能重复的答案不同!请不要在没有任何想法的情况下对其进行标记。我通过遵循this在re-B中进行了以下操作:

git remote add repo-A url-to-repo-A
git fetch repo-A --tags
git merge --allow-unrelated-histories repo-A/master

但是,出现以下错误:

Auto-merging package.json
CONFLICT (add/add): Merge conflict in package.json
Auto-merging package-lock.json
CONFLICT (add/add): Merge conflict in package-lock.json
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Auto-merging .gitignore
CONFLICT (add/add): Merge conflict in .gitignore
Automatic merge failed; fix conflicts and then commit the result.

我该如何解决?

1 个答案:

答案 0 :(得分:0)

问题:两个存储库A和B中的文件是否应该是相同的文件?还是要将A中的所有文件添加为子目录并保存为单独的文件?

解决方案1:是的,它们是相同的文件,并且那些文件需要合并。 在这种情况下,您需要编辑文件以解决任何冲突。冲突标记<<<和>>>将添加到文件中。您需要编辑文件,以便它们包含合并后所需的内容。然后执行:

git add <file>
# after all file conflicts have been resolved and added
git commit

解决方案2:否,来自回购A的文件应全部位于单独的子目录中,并应与原始回购B中的文件分开。在这种情况下,您要将回购A作为子树导入回购B。使用git subtree命令:

git subtree add -P <prefix> <repository> <ref>

例如:

git subtree add -P repo-A-dir url-to-repo-A master
相关问题