git提交到遠程藏庫衝突解決

問題

在修改好文件,然後用命令$ git push 向github上的遠程倉庫推送時,出現下列錯誤:


error: failed to push some refs to 'https://github.com/GDDXZ/RobotDenso.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.


原因

兩人同時fetch了一個分支。 第一個人修改後提交,第二個人提交就失敗。

解決方法

1.強制推送

$ git push -f
可以提交,會將remote上第一個人的改動沖掉,比較暴力,不太好。

2.正常解決

先 git fetch origin 然後git merge origin/master, 和本地分支合併, 之後再push。

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