git常見錯誤處理
狀態不一致:Your branch is ahead of 'origin/master' by 2 commits
git push origin master
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'http://*.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 merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
現象:當檢視狀態時,或者pull拉取server上的版本時,提示本地commit沒有push:
# 檢視本地狀態資訊
git status
報錯
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
【分析】:
如果保證git server上確實已經提交了程式碼,僅僅只是本地git狀態不一致,則可以用以下命令:
git fetch - -all
git pull
git reset - -hard origin/master