在使用git 對文件進行push到gitHub時可能會出錯,信息如下
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://github.com/xxxxxx
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.
7)W4@WJ1AV06HL%39SQ1VX5.png
錯誤原因:
更新被拒絕,因為遠程倉庫包含本地沒有的部分。
可能你在另一個存儲庫推送到了遠程倉庫,但是現(xiàn)在用的這個本地存儲庫沒有跟遠程倉庫同步。
解決辦法:
你需要先同步遠程倉庫。使用 git pull
命令,取回遠程主機某個分支的更新,再與本地的指定分支合并。然后就可以push到遠程倉庫啦
git pull
完整格式如下:
git pull <遠程主機名> <遠程分支名>:<本地分支名>
- 取回遠程origin主機的next分支,與本地的master分支合并:
git pull origin next:master
- 遠程分支與當(dāng)前分支是合并關(guān)系時,本地分支名可以省略:
git pull origin next
- git clone時,所有本地分支默認與遠程主機的同名分支,建立追蹤關(guān)系(tracking),也就是本地的master分支自動"追蹤"遠程origin/master分支。此時可以省略遠程分支名:
git pull origin
- git clone后,當(dāng)前分支只有一個追蹤分支,可以省略遠程主機名,直接:
git pull
tips
之前遇到問題在網(wǎng)上找辦法的時候,不小心找到了個錯誤的,然后也沒發(fā)現(xiàn)問題,就這么用了,后來經(jīng)過辰輝~的提醒,又仔細查了查資料,終于搞明白了。
使用
git push -f origin master
命令,也是可以完成push推送的!?。?br> 但是!??!
這個命令的作用是強制push,慎用?。∷侵苯影驯镜氐膒ush到遠程倉庫,然后把遠程倉庫中不同的地方全都抹掉覆蓋了。這種逆天的命令真是醉了呢,幸虧之前用這個命令的時候沒有造成什么損失。。