今天git回退版本, 導(dǎo)致線上分支和線下分支不一致導(dǎo)致git上傳不上去.
我使用強(qiáng)制推送將線下版本同步到線上版本. 但是這樣也丟失了幾個(gè)commit修改. 在多人協(xié)助的時(shí)候很不可取, 多人協(xié)助最好在低的commit版本上開一個(gè)分支修改后上傳然后同步.
$ git push -u origin master
To git@github.com:******/Demo.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:******/Demo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
網(wǎng)上搜索了下,是因?yàn)檫h(yuǎn)程repository和我本地的repository沖突導(dǎo)致的,而我在創(chuàng)建版本庫后,在github的版本庫頁面點(diǎn)擊了創(chuàng)建README.md文件的按鈕創(chuàng)建了說明文檔,但是卻沒有pull到本地。這樣就產(chǎn)生了版本沖突的問題。
有如下幾種解決方法:
使用強(qiáng)制push的方法:
$ git push -u origin master -f
這樣會使遠(yuǎn)程修改丟失,一般是不可取的,尤其是多人協(xié)作開發(fā)的時(shí)候。
一般這種方法可以最有效的解決問題push前先將遠(yuǎn)程repository修改pull下來
$ git pull origin master
$ git push -u origin master若不想merge遠(yuǎn)程和本地修改,可以先創(chuàng)建新的分支:
$ git branch [name]
然后push
$ git push -u origin [name]
參考:
http://stackoverflow.com/questions/10298291/cannot-pushto-github-keeping-saying-need-merge