Git提交遇到non-fast-forward

好久不見發表於2018-07-27

今天想把電腦上的本地專案通過Git提交到Coding上面,在Coding上建立專案、初始化倉庫並自動建立了README.md檔案,然後本地提交時執行git push的時候,提示:

To https://git.coding.net/xxxx/xxx.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to `https://git.coding.net/xxxx/xxx.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.

提示push失敗,在push執行需要執行pull拉取遠端程式碼。然後執行git pull origin master

From https://git.coding.net/xxxx/xxx
 * branch            master     -> FETCH_HEAD
fatal: refusing to merge unrelated histories

意思是拒絕合併沒有聯絡的歷史,表明本地和遠端現在是兩個不同的專案。

解決方案(使用其中一種即可)
針對refusing to merge unrelated histories問題

#允許合併不相關的內容
$ git pull --allow-unrelated-histories

#提交內容
$ git push 

針對non-fast-forward問題

#強推,原生程式碼強行覆蓋遠端`git`倉庫
$ git push -f

相關文章