如何将我的新更改推送到我的 git 主存储库?

How can I push my new changes to my git master repository?

我在我的本地服务器上做了一些更改,我想将它推送到我的主存储库。这通常工作正常,但这次我收到一条错误消息:

Pushing to https://mypage.com/project.git To https://bitbucket.org/mypage/project.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'https://mypage.com/project.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 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. Completed with errors, see above

如果更换了遥控器,就会发生这种情况。其他人也在为您的项目工作吗?或者您是否有任何可能影响 master 的构建脚本?

使用 git stash 保存您的本地更改。 使用 git pull 从远程下拉更改 然后使用 git stash pop 取回您的工作。 现在您可以正常使用 git commitgit push

如果您 100% 确定您的本地工作包含所需的更改,您也可以使用 git push --force但要小心这个,因为它会覆盖遥控器上的任何更改。