在 GIT 中取消暂存和取消跟踪

Unstaging and untracking in GIT

我暂存了一个文件并取消暂存它,我使用了 git 重置。

但它并没有取消暂存文件,而是使文件处于 'untracked' 状态。

为什么会这样?

如果该文件之前未被跟踪,则将其取消暂存(意味着将其从索引中删除)会将其再次列为未跟踪。

由于 git reset 确实在 HEAD 重置了该文件的索引条目,并且该文件不是 HEAD 的一部分,因此未被跟踪。

当您 reset 使用 git reset 的文件时,该文件会 return 编辑到它在 HEAD 中的状态。如果文件不在 HEAD 中(未提交到 git 存储库),重置将 return 文件变为 untracked 状态。

如果您希望新文件被视为已被跟踪,您可以使用 git add -N 命令将文件标记为 有意添加

git add -N <file>

--intent-to-add
Record only the fact that the path will be added later. An entry for the path is placed in the index with no content. This is useful for, among other things, showing the unstaged content of such files with git diff and committing them with git commit -a.