This is usually caused by another repository pushing:refusing to merge unrelated histories

 事情是這樣的,我先是在一個git好了的目錄連接了一個倉庫創建了一個項目併發布到了那個倉庫上,然後我又在idea中創建了一個更完整的項目,又連接到了這個git倉庫中(倆項目名稱相同),然後就想發佈上去,結果add ,commit完成之後要push時,出現了這一幕

error: failed to push some refs to '我相關聯的git倉庫'
hint: Updates were rejected because the remote contains work that you do
!	refs/heads/master:refs/heads/master	[rejected] (fetch first)
Done
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

根據它的提示我大概知道是衝突了因爲之前提交的並不完整,我的本意是想用這個來覆蓋之前的,於是我就想先pull下來解決衝突(事實上我pull下來不會影響我這個項目因爲我在之前的目錄下把不完整的項目給刪除了,這個時候我的倉庫其實是空的,但是會遺留下git自己的備份數據比如備份的版本log),結果我在pull的時候發生瞭如下一幕

warning: no common commits
remote: 對象計數中: 101, 完成.        
remote: 壓縮對象中: 100% (87/87), 完成.        
remote: Total 101 (delta 43), reused 0 (delta 0)        
Receiving objects: 100% (101/101), 17.27 KiB | 0 bytes/s, done.
Resolving deltas: 100% (43/43), done.
From 我相關聯的git倉庫
 * branch            master     -> FETCH_HEAD
 * [new branch]      master     -> origin/master
fatal: refusing to merge unrelated histories
說是拒絕讓我合併不相關的歷史

解決方案:

執行如下命令

git pull origin master --allow-unrelated-histories

然後就會解決衝突,如果說你的倉庫項目跟你要上傳的項目有衝突那你就解決衝突再push(前面說了我的倉庫其實是空的只保留了git自己的log)

然後再push上去就成功了

Counting objects: 132, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (80/80), done.
Writing objects: 100% (132/132), 22.17 KiB | 0 bytes/s, done.
Total 132 (delta 56), reused 57 (delta 33)
remote: 處理 delta 中: 100% (56/56), 完成.        
To 我關聯的倉庫	bdd1ac7..30c6958
Done

git新手做如上筆記
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章