我使用以下过程有一段时间:
git fetch origin master
git merge origin/master
git push --dry-run origin master
git push origin master
现在这已经停止工作并产生此错误
To git@example.com:company/project/admin.git
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'git@example.com:company/project/admin.git'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
现在只有git pull有效,而不是fetch和merge。
为什么会发生这种情况?这种情况也发生在其他开发人员身上。
我认为这里的问题在于您正在执行:
git fetch origin master
它从origin
用master
更新FETCH_HEAD
,但不更新远程跟踪分支origin/master
。
你可能想做:
git fetch origin
相反,它将更新来自origin
的所有远程跟踪分支,包括origin/master
。
git fetch
的文档中对此进行了解释,但我认为可以公平地说,这让很多人感到困惑。。。