【Git】Updates were rejected because the remote contains work that you do

使用git push -u origin master,把本地代碼推送到遠程倉庫,出現如下錯誤

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.
 

這是因爲本地的代碼不是最新的,把遠程master最新的代碼更新到本地就可以了,

使用命令: git pull origin master 

之後又出現了錯誤:fatal: refusing to merge unrelated histories

解決方法:使用以下命令,強制合併

git pull origin master --allow-unrelated-histories

後面加上 --allow-unrelated-histories , 把兩段不相干的 分支進行強行合併

後面再push就可以了 

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