! [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.发布于 2022-11-20 18:07:29
TL;DR
更多细节
它们是密切相关的消息:在这两种情况下,您的本地分支与远程分支都不是最新的,您需要通过多种方法中的一种来修复它:git pull、git pull --rebase、git fetch +以您选择的方式更新您的本地分支。在第二种情况下,只要git merge或git rebase就足够了。
区别是:
origin/<branchname>远程跟踪分支已经落后。通过在本地进行检查,您根本就没有关于这些新提交的信息,而Git正在告诉您“等一下,自上次查看以来,遥控器上的一些东西发生了变化!”此时需要进行提取或拉,然后您应该决定如何将您的工作与新的远程工作结合起来。
origin/<branchname>与远程同步,但是没有将新提交合并到<branchname>中。在这种情况下,您在本地拥有所有的信息,但还没有处理它。也许你想要合并,或重新基地,甚至可能是用力推,如果你确定这是你需要做的。但是,实际上并不需要提取或拉扯。
正如@jmargolisvt所说,git pull将修复这两种情况,但我更喜欢的方法是使用图形日志查看器检查新历史记录,然后使用图形日志查看器检查新历史记录,然后通常是重基,很少是合并。(我喜欢我的历史主要是线性的,我倾向于对PR使用合并提交,但没有太多其他。)
https://stackoverflow.com/questions/74510545
复制相似问题