鍍金池/ 問答/Linux  網(wǎng)絡(luò)安全/ git push本地項目到服務(wù)器報錯

git push本地項目到服務(wù)器報錯

我想將本地項目上傳到gitee上去,服務(wù)器上只有一個README.md.

$git push -u origin master
....//省略用戶名和密碼
! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'https://gitee.com/chopin406/myweb.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.

這個怎么處理呢

回答
編輯回答
葬愛

your current branch is behind its remote counterpart

你當前的本地分支已經(jīng)落后與你的遠程副本, SO. git pull

2017年9月16日 09:35
編輯回答
敢試

一、原因

應(yīng)該是你在clone之后改動了gitee上的README.md文件,并且本地也改動了README.md,導(dǎo)致本地的git倉庫和gitee倉庫的README.md文件產(chǎn)生沖突。

二、解決步驟如下
1、更新代碼:

git pull origin master
這時候會提示自動合并失敗,README.md文件文件存在沖突,報錯如下

Auto-merging README.md 
CONFLICT (add/add): Merge conflict in README.md
Automatic merge failed; fix conflicts and then commit the result.

2、解決沖突:本地打開README.md文件,會出現(xiàn)如下錯誤

  1 <<<<<<< HEAD
  2 2222222
  3 =======
  4
  5 init
  6 >>>>>>> 2f3ba214fb

“<<<<<<< HEAD”到“=======”是你本地改動的內(nèi)容,“=======”到 “>>>>>>> 2f3ba214fb"之間是gitee改動內(nèi)容。
選擇自己要保存的代碼內(nèi)容,刪除=======和>>>>>>>符號
最后執(zhí)行

git add README.md
git commit -m '解決README.md沖突'

備注
1、HEAD表示本地倉庫當前指針,2f3ba214fb表示指向遠程master分支的指針SHA-1值
2、在git沖突解決中,只要執(zhí)行add和commit操作后,git就默認你已經(jīng)解決了沖突

2017年6月11日 10:46
編輯回答
有你在

不論是svn還是git,先拉代碼,再push,這才是正確的操作步驟

2017年10月1日 14:45
編輯回答
尐潴豬

git pull 一下,如果有沖突,解決沖突之后git add然后git commit提交,如果沒有沖突不用管,然后再git push就行了

2018年5月3日 12:48
編輯回答
瘋浪

如果需要強制推送,使用 git push -u origin master -f

2018年7月15日 04:08
編輯回答
嘟尛嘴

按照報錯的提示,先進行pull,再嘗試使用push

2017年2月10日 23:35
編輯回答
荒城

遠程服務(wù)器的文件發(fā)生了變化 先pull下來 然后在push

2018年2月8日 02:42
編輯回答
柒喵

題主還是需要多看看git的文檔,多踩幾次坑就ok了

2018年7月1日 04:21