Git: 合并两个历史有冲突的回购
Git: Merging two repo with history having conflits
项目在 11 月份有大约 133 次提交,我克隆了项目并在 50 次提交之前创建了一个新的 repo,这意味着:
A----B----C----D----E
Cloned New Repo from C
\__ C
现在新仓库中大约有 15-20 次提交,但是没有提交被推送到旧仓库,而是在编写许多文件并在内部更改时。
A----B----C----D----E
Cloned New Repo from C
\__ C----C1----C2---C3---C4
现在我想将这两个 repo 合并为一个:
A----B----C----D----E----C1----C2---C3---C4
在互联网上搜索后得到一些命令并尝试与以下内容合并:
git --git-dir=../<some directory>/.git|
format-patch -k -15 --ignore-space-at-eol --stdout <commit SHA>|
git am -k -3
它给出了 First commit 的 confilts 并成功解决了它:
git mergetool
gm am --continue
显示错误:
Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Cannot fall back to three-way merge.
Patch failed at 0002 XXXXXXX
The copy of the patch that failed is found in:
/xxxxxx/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
如果可能,如何解决这个问题?
还有其他方法可以解决这个问题吗?
我会避免 'am' 方法——如果你真的有共同的历史,你应该利用 rebase、merge 或 cherry。
假设您在 E 有一家名为 'master'
的分行
将第二个存储库作为远程存储库添加到第一个存储库。假设我将新遥控器命名为 'sandbox'。
获取 --all
现在在 sandbox/C4 创建一个新的本地分支..假设分支名为 'otherwork'。检查该分支并在 'master' 之上进行变基。如果您在解决任何问题时遇到问题,您可以检查 master 并一次从 'otherwork' 分支中挑选一个更改。
项目在 11 月份有大约 133 次提交,我克隆了项目并在 50 次提交之前创建了一个新的 repo,这意味着:
A----B----C----D----E
Cloned New Repo from C
\__ C
现在新仓库中大约有 15-20 次提交,但是没有提交被推送到旧仓库,而是在编写许多文件并在内部更改时。
A----B----C----D----E
Cloned New Repo from C
\__ C----C1----C2---C3---C4
现在我想将这两个 repo 合并为一个:
A----B----C----D----E----C1----C2---C3---C4
在互联网上搜索后得到一些命令并尝试与以下内容合并:
git --git-dir=../<some directory>/.git|
format-patch -k -15 --ignore-space-at-eol --stdout <commit SHA>|
git am -k -3
它给出了 First commit 的 confilts 并成功解决了它:
git mergetool
gm am --continue
显示错误:
Did you hand edit your patch?
It does not apply to blobs recorded in its index.
Cannot fall back to three-way merge.
Patch failed at 0002 XXXXXXX
The copy of the patch that failed is found in:
/xxxxxx/.git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
如果可能,如何解决这个问题?
还有其他方法可以解决这个问题吗?
我会避免 'am' 方法——如果你真的有共同的历史,你应该利用 rebase、merge 或 cherry。
假设您在 E 有一家名为 'master'
的分行将第二个存储库作为远程存储库添加到第一个存储库。假设我将新遥控器命名为 'sandbox'。
获取 --all
现在在 sandbox/C4 创建一个新的本地分支..假设分支名为 'otherwork'。检查该分支并在 'master' 之上进行变基。如果您在解决任何问题时遇到问题,您可以检查 master 并一次从 'otherwork' 分支中挑选一个更改。