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