git 出現(xiàn) fatal: refusing to merge unrelated histories 錯誤

引用

git pull 失敗 ,提示:fatal: refusing to [merge](https://www.centos.bz/tag/merge/) unrelated histories

其實(shí)這個(gè)問題是因?yàn)?兩個(gè) 根本不相干的 git 庫, 一個(gè)是本地庫, 一個(gè)是遠(yuǎn)端庫, 然后本地要去推送到遠(yuǎn)端, 遠(yuǎn)端覺得這個(gè)本地庫跟自己不相干, 所以告知無法合并

具體的方法, 一個(gè)種方法: 是 從遠(yuǎn)端庫拉下來代碼 , 本地要加入的代碼放到遠(yuǎn)端庫下載到本地的庫, 然后提交上去 , 因?yàn)檫@樣的話, 你基于的庫就是遠(yuǎn)端的庫, 這是一次update

第二種方法:
使用這個(gè)強(qiáng)制的方法

git pull origin [master](https://www.centos.bz/tag/master/) --allow-unrelated-histories

后面加上 --allow-unrelated-histories , 把兩段不相干的 分支進(jìn)行強(qiáng)行合并

后面再push就可以了 [git push](https://www.centos.bz/tag/git-push/) [gitlab](https://www.centos.bz/tag/gitlab/) master:init

gitlab是別名 , 使用

git remote add gitlab ssh://xzh@192.168.1.91:50022/opt/gitrepo/withholdings/WithholdingTransaction

master是本地的branch名字
init是遠(yuǎn)端要推送的branch名字

本地必須要先add ,commit完了 才能推上去

關(guān)于這個(gè)問題,可以參考http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories。

在進(jìn)行g(shù)it pull 時(shí),添加一個(gè)可選項(xiàng)

git pull origin master --allow-unrelated-histories

============================================================================================================================


?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容