无法变基:您有未暂存的更改 git

13

我正在名为new_nlp的分支上,当我执行git status时,我得到以下提示:

# On branch new_nlp
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   deleted:    untitled.

这个文件已经被删除,我无法看到它的内容。

我想切换到主分支并从新的nlp分支执行一次变基操作,但当我切换到主分支并输入以下命令时:

git rebase new_nlp

我收到以下错误信息:

cannot rebase: you have unstaged changes
D   untitled.

我无法看到这个文件,也不知道如何删除它。我也不知道它是怎么被添加进来的。

有没有人知道我如何才能克服这个障碍?我不知道为什么这个文件仍然存在于索引中。

2个回答

16

该文件已被删除并已被git追踪。您可以:

  1. 删除该文件并提交更改 (git rm --cached untitled; git commit) 或
  2. 运行git checkout -- untitled以恢复该文件

太好了。我在这上面纠结了30分钟。 - kikuchiyo

2

使用git rm untitled将其从索引中移除。


1
git 很可能会抱怨。要么使用 --cached-f 选项。 - knittl

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接