在git重新启动/开发过程中,git显示以下错误消息:
fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef
我的Git版本是2.9.0。它在以前的版本中运行良好。
我如何才能继续使用新版本中引入的强制标志来允许不相关的历史?
在git重新启动/开发过程中,git显示以下错误消息:
fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef
我的Git版本是2.9.0。它在以前的版本中运行良好。
我如何才能继续使用新版本中引入的强制标志来允许不相关的历史?
当前回答
由于所有其他答案实际上都没有回答这个问题,所以这里有一个由这个相关问题的答案启发的解决方案。
因此,您在执行git rebase时出错:
$ git rebase origin/development
fatal: refusing to merge unrelated histories
Error redoing merge 1234deadbeef1234deadbeef
此错误实际上并没有取消基,但您现在正处于其中:
$ git status
interactive rebase in progress; onto 4321beefdead
Last command done (1 command done):
pick 1234deadbeef1234deadbeef test merge commit
现在您可以手动进行合并。查找原始合并提交的父提交:
$ git log -1 1234deadbeef1234deadbeef
commit 1234deadbeef1234deadbeef
Merge: 111111111 222222222
Author: Hans Dampf
Date: Wed Jun 6 18:04:35 2018 +0200
test merge commit
找出两个合并父级中的哪一个是合并到当前父级的父级(可能是第二个,请使用git日志222222222进行验证),然后手动进行合并,复制原始合并提交的提交消息:
$ git merge --allow-unrelated 222222222 --no-commit
Automatic merge went well; stopped before committing as requested
$ git commit -C 1234deadbeef1234deadbeef
[detached HEAD 909af09ec] test merge commit
Date: Wed Jun 6 18:04:35 2018 +0200
$ git rebase --continue
Successfully rebased and updated refs/heads/test-branch.
其他回答
我在第一次设置本地存储库时遇到了这个错误。然后我去了GitHub并创建了一个新的存储库。然后我跑了
git remote add origin <repository url>
当我尝试推或拉时,我每次都会遇到同样的致命错误:unlated_histories错误。
以下是我修复它的方法:
git pull origin master --allow-unrelated-histories
git merge origin origin/master
... add and commit here...
git push origin master
在管理员在服务器端通过几百次提交将开发分支强制推送给origin/master之后,我遇到了这个错误。
嗯,我只是不想拉(fetch+merge),而是想将本地主机与远程源主机对齐。移动到一个单独的文件夹并进行Git克隆是一种方法,但我认为仅进行硬重置是更优雅的解决方案。
因此,我对这个错误的回答,在这个特定的例子中,不是上述任何一种。
我只是想要这个:
git reset --hard origin/master
我也有同样的问题。问题很遥远,有一些东西阻止了这一点。
我首先创建了一个本地存储库。我将LICENSE和README.md文件添加到本地并提交。
然后我想要一个远程存储库,所以我在GitHub上创建了一个。在这里,我错误地选中了“用README初始化这个存储库”,这也在远程创建了一个README.md。
所以现在当我跑步时
git push --set-upstream origin master
我得到了:
error: failed to push some refs to 'https://github.com/lokeshub/myTODs.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.
现在为了克服这一点,我做到了
git pull origin master
导致以下错误:
From https://github.com/lokeshub/myTODs
branch master -> FETCH_HEAD
fatal: refusing to merge unrelated histories**
我尝试了:
git pull origin master --allow-unrelated-histories
结果:
From https://github.com/lokeshub/myTODs
* branch master -> FETCH_HEAD
Auto-merging README.md
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed;
fix conflicts and then commit the result.
解决方案:
我删除了远程存储库,并创建了一个新的(我认为只有删除文件README才能起作用),之后,以下操作奏效:
git remote rm origin
git remote add origin https://github.com/lokeshub/myTODOs.git
git push --set-upstream origin master
我也犯了同样的错误,这个命令对我有效:
git pull gitlab master --allow-unrelated-histories
请注意,在您的案例中,gitlab可能是origin或heroku。
blue112的答案并不能解决这个问题,这是在重新定基的背景下。
同步两个分支的唯一方法是将它们合并在一起,从而产生一个额外的合并提交和两组包含相同更改的提交(原始提交和来自重新基础分支的提交)。不用说,这是一个非常令人困惑的情况。
因此,在运行git-rebase之前,请先问问自己,“还有人在看这个分支吗?”如果答案是肯定的,请把手从键盘上拿开,开始思考一种非破坏性的方法来进行更改(例如,git-restore命令)。否则,你可以随心所欲地重写历史。
参考资料:回扣的黄金法则