如何在本地强制合并两个远程分支?



我正试图从不同的存储库合并我的本地分支到我的上游代码。我想在我的开发系统中合并priv/dev分支到origin/master。我想优先考虑我的修改而不是原始主控。然而它失败了,我的代码有错误吗?

git clone https://github.com/production public_code
cd public_code
git remote add priv https://gitlab.com/tmv/development
git merge -Xours priv/dev origin/master

输出
error: Merging is not possible because you have unmerged files.
hint: Fix them up in the work tree, and then use 'git add/rm <file>'
hint: as appropriate to mark resolution and make a commit.
fatal: Exiting because of an unresolved conflict.

由于您只克隆了一个repo,您只需要执行常规合并:

git clone https://github.com/production public_code
cd public_code
git remote add priv https://gitlab.com/tmv/development
git merge -Xtheirs priv/dev
git push origin HEAD

克隆后,主分支将被检出,并且您已经拥有了最新的master分支。

git merge将当前本地分支与您在命令行中给出的任何分支合并。您不能真正合并上游分支。因此,在您的示例中,您将priv/devorigin/master合并到本地master分支中。相反,您需要合并这些分支的本地副本,然后将最终结果推送到上游repo:

git clone <repo URL>
cd <repo dir>
git checkout <branch you want to merge into>
git merge <branch you want to merge>
git push

最新更新