今天想把電腦上的本地專案通過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