我在尝试将项目推送到 GIT 上时遇到以下问题。
推送它我收到此错误消息:
$ git push origin master
To https://bitbucket.org/MyAccount/my-project.git
! [rejected] master -> master (fetch first)
error: failed to push some refs to 'https://MyAccount@bitbucket.org/MyAccount/my-projec.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.
所以看起来,如果我做错了断言,请纠正我,在我的远程存储库中有我没有在本地存储库中进行的更改,它建议我执行 pull 以获取这些更改。
这对我来说是个问题,因为本地版本是我应用程序的最后一个最终版本,我不能冒险覆盖远程存储库中旧的和错误的(或由其他人制作的)东西。
是否可以指定推送本地内容而不考虑远程变化?或者我如何检查我上次本地提交和远程内容之间的差异?
最佳答案
是的,正如你所理解的,这是因为远程 master
分支有新版本(可能是你的同事推送的)。并且不能忽略新版本,除非强行推送,否则会导致新版本丢失。
您应该将新版本从远程 pull 到本地,并将未推送的提交 rebase 到新版本的顶部,如果在 git pull 期间发生冲突,则将冲突文件保留为本地版本,您可以使用该命令
git pull origin master --rebase -X theirs
您可以使用跟踪分支 来检查远程是否有新版本。 master
分支通常跟踪到origin/master
(可以通过git branch –vv
查看)。然后你可以使用git status
,git会比较本地master和远程分支。
关于git - 如何在 GIT 推送期间忽略远程更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43777849/