假设我的 git 存储库中有一个名为 foo
的文件。
假设已经用rm
(不是git rm
)删除了。然后 git status 会显示:
Changes not staged for commit:
deleted: foo
如何暂存这个单独的文件删除?
如果我尝试:
git add foo
它说:
'foo' did not match any files.
更新(9年后,哈哈):
这看起来已经在 git 2.x 中修复了:
$ git --version
git version 2.25.1
$ mkdir repo
$ cd repo
$ git init .
Initialized empty Git repository in repo/.git/
$ touch foo bar baz
$ git add foo bar baz
$ git commit -m "initial commit"
[master (root-commit) 79c736b] initial commit
3 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 bar
create mode 100644 baz
create mode 100644 foo
$ rm foo
$ git status
On branch master
Changes not staged for commit:
deleted: foo
$ git add foo
$ git status
On branch master
Changes to be committed:
deleted: foo
最佳答案
使用 git rm foo
暂存文件以供删除。 (这也会从文件系统中删除该文件,如果它之前没有被删除的话。当然,它可以从 git 中恢复,因为它之前已经被 checkin 了。)
要暂存要删除的文件而不将其从文件系统中删除,请使用 git rm --cached foo
关于git - 暂存删除的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12373733/