git - `git pull` 失败,现有历史记录为 "Not possible to fast-forward"

标签 git

我已经阅读了很多关于主题错误消息(“不可能快进”)的其他问题,但似乎没有一个适用于我的情况。我创建一个分支 (git checkout -b issue-215),进行更改,然后在本地提交。我推送更改,然后进行新的更改和另一个本地提交:

* 4b797d2a - (HEAD -> issue-215) 
* 180a7ab5 - (origin/issue-215)
* 863ef01a - (origin/master, origin/HEAD, master)

预计到达时间:根据评论中的要求,git branch --all -v 的输出:

* issue-215                 4b797d2a [ahead 1] 
  ... other branches ...
  master                    863ef01a 
  
  remotes/origin/issue-215  180a7ab5 
  ...other remotes....
  remotes/origin/HEAD       -> origin/master
  remotes/origin/master     863ef01a 

没有新的远程更改,但 VSCode 希望在推送之前先 pull 。那就是我收到此错误的地方。因此,为了排除故障,我手动运行 git pull origin issue-215,并获得以下输出:

$ git pull origin issue-215
From ssh://my.repo/project
 * branch              issue-215  -> FETCH_HEAD
fatal: Not possible to fast-forward, aborting.

请记住,服务器上没有新的更改,并且从我当前本地提交的历史记录返回到远程分支,返回到 masterorigin/master,是一条直线。我不是要 merge 或 rebase ,我的本地代码已经是我应该 pull 的分支的直接子代码。

这大约在一个月前才开始发生。以前,单击 VSCode 中的“同步”按钮会起作用,但从那时起它总是失败并显示此错误消息。我是否可以进行某种导致此行为的 gitconfig 更改?我的全局 gitconfig 文件中没有太多内容,而且至少有 2 个项目会发生这种情况,所以我认为这不是我对存储库所做的事情。

最佳答案

这是 Git 版本 2.33.1 的一个已知问题。它应该在 2.33.2 中修复。 其他通常有用的建议如下:


“无法快进”消息意味着您将 git pull 配置为使用 git merge --ff-only,可能使用 git仅配置 pull.ff。所以 git pull 尽职尽责地运行:

git fetch origin issue-215
git merge --ff-only FETCH_HEAD

第二个命令给出错误并停止。 (编辑:如果您自己手动执行此操作并且它有效,则您遇到了脚注 1 中的错误。)

Keep in mind, there are no new changes on the server, and the history from my current local commit back to the branch on the remote, back to master and origin/master, is a straight line.

很明显(根据错误),它不是1 获取后,运行:

git log --all --graph --decorate --oneline FETCH_HEAD

看看哪里它不是; 为什么它不是另一个问题。我怀疑答案是这样的:

  • 来源是GitHub;
  • 其他人正在使用 REBASE AND MERGESQUASH AND MERGE 按钮;
  • 因此您使用 fetch 获得的提交在逻辑上等同于您之前推送的提交,但具有不同的哈希 ID.

常规 merge 或 rebase 会起作用,但 ff-only 不会。 (这不是唯一可能的解释:例如,其他托管站点具有相同的效果,但有时按钮标签不同。)

This only started happening about a month ago. Previously, clicking the "sync" button in VSCode would work, but since then it always fails with this error message. Could I have made some kind of gitconfig change that causes this behavior?

它可能是您更改的内容,例如将 pull.ff 设置为 only。它可能是其他人更改的,例如从 GitHub 上的 MERGE 切换到 REBASE AND MERGE


1Git 2.33.1 中有一个错误,其中 pull.ff only 拒绝了它不应该有的空操作情况。如果你有 Git 2.33.1,要么升级它,要么使用 git fetch,然后在这种情况下使用 git merge --ff-only

关于git - `git pull` 失败,现有历史记录为 "Not possible to fast-forward",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69828306/

相关文章:

linux - 如何将一个存储库中的单个 git 提交应用到另一个存储库?

git - 重写 Git 历史的实际后果是什么?

git - 尝试使用 git filter-branch 修复行尾,但没有运气

git - 当找不到远程存储库时,防止 git pull 从 github 请求用户名密码

git - 如何将我的项目重新连接到我现有的 GitHub 存储库

Git 压缩和 merge

git - "Keeping up"与远程主机在长期本地主题分支上工作时

git - Heroku - MacOS Toolbest - 多个 heroku 帐户 ssh key 问题

linux - 错误打印消息

git - 在 Git 分支之间复制代码