假设我在git仓库中有一个名为foo
的文件。
如果使用rm
(而不是git rm
)删除了该文件,则git状态将显示:
Changes not staged for commit:
deleted: foo
如何分阶段删除单个文件?
如果我尝试:
git add foo
It says:
'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 add foo
现在可以工作了。请参见更新。 - Andrew Tomazos