无法合并github中的2个分支:没有任何东西可以比较

问题描述 投票:0回答:1

我用主分支创建了一个存储库,当我准备推送代码时,我不小心创建了另一个分支 -

master
。现在,当我尝试合并 2 个分支时,我收到消息:

Github merge

我也收到提示:

commit history

另外,当我尝试

git push
进入主目录时,我收到错误:

! [rejected]        main -> main (non-fast-forward)
error: failed to push some refs to 'https://github.com/ATFUSA/ATFUSA.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
github commit branching-and-merging
1个回答
0
投票

尝试:

git pull
git checkout main
git merge master --allow-unrelated-histories
git push <upstream> main -f

显然,将

<upstream>
替换为您的存储库。

这里的关键是

--allow-unrelated-histories
。默认情况下,git 不允许您合并两个完全不同的分支,以防止错误地合并两个不同的项目,但这将覆盖该保护。 Push 命令中的
-f
是强制推送,然后确保 GitHub 不会拒绝推送。请参阅文档了解更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.