參考:https://blog.csdn.net/u012145252/article/details/80628451
https://blog.csdn.net/lindexi_gd/article/details/52554159
git pull 失敗 ,提示:fatal: refusing to merge unrelated histories
其實這個問題是因爲 兩個 根本不相干的 git 庫, 一個是本地庫, 一個是遠端庫, 然後本地要去推送到遠端, 遠端覺得這個本地庫跟自己不相干, 所以告知無法合併
具體的方法, 一個種方法: 是 從遠端庫拉下來代碼 , 本地要加入的代碼放到遠端庫下載到本地的庫, 然後提交上去 , 因爲這樣的話, 你基於的庫就是遠端的庫, 這是一次update了
第二種方法:
使用這個強制的方法
git pull origin master --allow-unrelated-histories
後面加上 --allow-unrelated-histories
, 把兩段不相干的 分支進行強行合併
後面再push就可以了 git push gitlab master:init
gitlab是別名 , 使用
Java代碼git remote add gitlab ssh://[email protected]:50022/opt/gitrepo/withholdings/WithholdingTransaction
master是本地的branch名字
init是遠端要推送的branch名字
本地必須要先add ,commit完了 才能推上去
關於這個問題,可以參考http://stackoverflow.com/questions/37937984/git-refusing-to-merge-unrelated-histories。
在進行git pull 時,添加一個可選項
git pull origin master --allow-unrelated-histories