Git解決push失敗

錯誤信息:

Administrator@YLMF-2019PQDZXZ MINGW64 /f/workspace/demo (master)
$ git push origin master
fatal: HttpRequestException encountered.
   An error occurred while sending the request.
Username for 'https://github.com': cherispanty
To https://github.com/cherispanty/demo.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://github.com/cherispanty/demo.git'
hint: Updates were rejected because the remote contains work that you do
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.

可以看到我push到遠程倉庫失敗了,原因是我的這個版本不是服務器上最新的版本,恰巧我本地的代碼和遠程倉庫的代碼在同一個文件的同一行做了修改,因此產生了衝突,這是我們應該先使用git pull命令更新最新的代碼再上傳。
然後我pull一下,發現產生了衝突:
在這裏插入圖片描述
如何解決?打開衝突的文件,刪除不必要的部分(不要亂刪別人的代碼,最好和別人協商一下),保存退出文件
在這裏插入圖片描述
這是我的修改:
在這裏插入圖片描述
再add,commit,push。(注意commit操作不要加文件名)
在這裏插入圖片描述
最後發現可以push成功了~

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