bbb
bbb
使用以下命令将更改推送到远程存储abc
库分支:
git push origin bbb:abc
Run Code Online (Sandbox Code Playgroud)
效果很好。
然后使用以下命令将更改推送到远程存储库主分支:
git push origin bbb:master
Run Code Online (Sandbox Code Playgroud)然后出现以下错误消息:
! [rejected] bbb -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/sw7x/testing4.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.
Run Code Online (Sandbox Code Playgroud)
有人能解释为什么会发生这种情况吗?
正如 git 本身所说:
hint: (e.g. 'git pull ...') before pushing again.
Run Code Online (Sandbox Code Playgroud)
首先pull
(甚至fetch
)从 master 开始,进行所需的更改,最后push
。如果你是一个刻薄的人并且不关心别人的改变,你可以使用push -f
强制推动。
出现此错误的原因是您的本地版本与 github 存储库中的版本不同,您应该以某种方式协调这两个版本以便能够使用push
您的代码。