git · Git
报错原文
Updates were rejected because the remote contains work that you do not have locally.
这是什么意思
这是 push 被拒的原因说明:远端有你的克隆没有的工作,现在推上去会把它删掉。它出现在多人共用一条分支时,或者你在网页上改文件提交后一直没拉下来。先 git pull --rebase origin main,再 push,就顺利通过了。不理这条提示而加 --force,正好做了提示要防的事:别人的提交从服务器上消失,而如果他 push 之后没人 fetch 过,这些提交就哪里都不剩了。
怎么修
git pull --rebase origin main- 来自
- git
- Git
- 29
git 的错误几乎都是一种拒绝,意思是「在当前状态下做那件事会丢掉东西」;fatal: 表示它什么都没改就停了,而真正的解决办法往往在第一行下面的 hint: 行里。
怎么读报错
- 从第一行往下读。越往下越是工具内部的事,起因通常写在最上面。
- 有文件名和行号就从那里查——不是栈顶那一帧,而是最上面那条提到你自己写的文件的行。
- 把报错原文照样去搜,但先去掉你自己的路径和变量名,正是那些让搜索匹配不上。
- 同一种情况在不同版本里措辞不同。结果不对头,就把版本号一起加进查询。
- 粘贴修法之前,先确认它会丢掉什么。这里面有些是不能撤回的。
常见问题
Q. “Updates were rejected because the remote contains work that you do not have locally.” 是什么意思?
这是 push 被拒的原因说明:远端有你的克隆没有的工作,现在推上去会把它删掉。它出现在多人共用一条分支时,或者你在网页上改文件提交后一直没拉下来。先 git pull --rebase origin main,再 push,就顺利通过了。不理这条提示而加 --force,正好做了提示要防的事:别人的提交从服务器上消失,而如果他 push 之后没人 fetch 过,这些提交就哪里都不剩了。
Q. 怎么修?
git pull --rebase origin main —— 执行前先看上面的说明,确认这条命令会丢掉什么。
Q. 这是哪个工具报的?
git。它属于Git,报错原文有 14 个词。
相关报错
! [rejected] main -> main (fetch first)giterror: failed to push some refs to 'https://github.com/user/repo.git'giterror: src refspec main does not match anygitfatal: The current branch feature has no upstream branch.giterror: cannot lock ref 'refs/remotes/origin/main': is at 8a3f21c but expected 1c2d3e4gitfatal: not a git repository (or any of the parent directories): .gitgitfatal: remote origin already exists.giterror: pathspec 'featue' did not match any file(s) known to gitgit