如何解决 "git status" 未显示的未暂存更改

How to resolve unstaged changes not shown by "git status"

考虑

$ git status
On branch chore/nbsp-fix-2
nothing to commit, working directory clean
$ git rebase -i master
Cannot rebase: You have unstaged changes.
Please commit or stash them.

我如何找出阻止 git 变基的未暂存更改是什么?

一些背景:有人设法添加名称中包含不间断 space (%A0) 的文件。这导致存储库出现问题。文件显示为未跟踪,git 认为存储库不干净 — 类似的问题。

我用来纠正问题的技术是在进行这些更改之前创建一个新分支,并在这些更改之后挑选少数提交。不幸的是,我现在处于这种情况。我可以想象还有一些其他文件或该问题的其他残余物阻止我继续前进。在错误文件名之后挑选单个提交之后,我现在处于这个位置。

我正在寻找解决此问题的建议。什么是 rebase 看到那个 status 没看到?

原来 git rebase/usr/libexec/git-core/git-rebase 中的一个 shell 脚本,在 git-sh-setup 中为 "have unstaged changes" 在那个目录中搜索恰好一次命中这个函数:

require_clean_work_tree () {
    git rev-parse --verify HEAD >/dev/null || exit 1
    git update-index -q --ignore-submodules --refresh
    err=0

    if ! git diff-files --quiet --ignore-submodules
    then
        echo >&2 "Cannot : You have unstaged changes."
        err=1
    fi

[ ... ]

rebase 确实调用了它。所以,回答

What is rebase seeing that status does not see?

你的问题,试试git diff-files

与 OP 的问题不太相关,但希望这对其他人有用。在我的例子中,git status 在某个文件夹下的回购中没有看到 新文件 。它们可以手动上演,但在取消上演时再次消失。原因是在 .git/info/exclude 文件中找到的,该文件不知何故是非空的,显然是由我以前的一个 IDE 生成的,很久以前。