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



原文地址:https://www.cnblogs.com/songyuejie/p/14122062.html