这个变基从何而来?

Where does this rebase come from?

我最近在本地创建了一个新分支,将其发布到远程,并收到同事的更新。 虽然我的存储库中确实有更改,但其中 none 是在已修改的文件上。 因此,我预计 git pull 会像来自 git status:

的消息所暗示的那样工作
$ git status
On branch XXX
Your branch is behind 'origin/XXX' by 2 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
    modified:   ...

但是,拉取会导致一条错误消息,暗示正在进行变基:

$ git pull
error: cannot pull with rebase: You have unstaged changes.
error: please commit or stash them.

我不知道这可能是从哪里来的,因为我从来没有有意识地做过变基。 还有,奇怪的是:

$ git rebase --continue
fatal: No rebase in progress?

我可以在存储我的更改并在之后弹出它们时毫无问题地拉取它们,并且知道自动存储选项,但我想了解这里发生了什么。

变基从何而来? 为什么git pull 和git rebase 似乎不同意是否有rebase? 我怎样才能收拾这个烂摊子?

您可能在拉动时自动启用了变基。尝试

git config pull.rebase
git config --global pull.rebase

看看两者是否 true。如果是这样,你可以这样做:

git config pull.rebase false
git config --global pull.rebase false

(或使用--unset

Where did the rebase come from?

作为 Git 配置文件中的 , you have likely configured git pull to do a rebase instead of a merge by setting the pull.rebase 选项(全局或当前存储库)。

Why do git pull and git rebase appear to disagree whether there is a rebase?

他们没有。 git pull 只是拒绝执行变基,因为您的工作目录中有未提交的更改。到 git pull 退出时,没有正在进行的变基。

How can I clean up this mess?

您可以在执行 git pull 之前提交或存储您的更改(rebase.autostash option that you mentioned will do the latter for you automatically). Alternatively, you could set pull.rebase to false and have git pull do a regular merge, but I wouldn't recommend it