- “遠程包含您在本地沒有的作業”
! [rejected] feature/addition -> feature/addition (fetch first)
error: failed to push some refs to 'github.com:<github_username>/<reponame>.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.
- “你當前分支的尖端在它的遠程分支后面”
! [rejected] feature/addition -> feature/addition (non-fast-forward)
error: failed to push some refs to 'github.com:<github_username>/<reponame>.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
uj5u.com熱心網友回復:
長話短說
“遠程包含你在本地沒有的作業”意味著自上次獲取以來遠程發生了變化。
“你當前分支的尖端在它的遠程分支后面”意味著你已經從遠程獲取更改但還沒有處理它們。
更多詳情
它們是密切相關的訊息:在這兩種情況下,您的本地分支都不是遠程分支的最新資訊,您需要通過多種方式之一修復該問題:git pull, git pull --rebase, git fetch 以您選擇的方式更新您的本地分支。在第二種情況下,只是git merge或git rebase也足夠了。
區別在于:
第一條訊息說您甚至還沒有從遠程獲取那些新提交,并且您的本地
origin/<branchname>遠程跟蹤分支落后了。通過僅在本地檢查,您根本沒有關于這些新提交的資訊,并且 Git 告訴您“等一下,自從您上次查看以來,遠程上發生了一些變化!”此時需要獲取或拉取,然后您應該決定如何將您的作業與新的遠程作業結合起來。
第二條訊息說你確實從遠程獲取,并且
origin/<branchname>與遠程同步,但你沒有將新提交合并到<branchname>. 在這種情況下,您在本地擁有所有資訊,但您還沒有對其進行處理。也許你想合并、變基,或者如果你確定這是你需要做的,甚至可能強制推送。但實際上并不需要獲取或拉取。
正如@jmargolisvt 所說,agit pull將解決這兩種情況,但我的首選方法是git fetch使用圖形日志查看器檢查新歷史記錄,然后通常是 rebase,很少是合并。(我喜歡我的歷史大部分是線性的,我傾向于對 PR 使用合并提交,但其他的不多。)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537643.html
標籤:混帐知乎推
上一篇:GIT初始化和連接到Github
