削除されたファイルのステージング 質問する

削除されたファイルのステージング 質問する

たとえば、git リポジトリに というファイルがあるとしますfoo

rm(not )で削除されたとします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

ベストアンサー1

削除するファイルを準備するために使用しますgit rm foo。(ファイルが以前に削除されていない場合は、これによりファイル システムからもファイルが削除されます。もちろん、以前にチェックインされているため、git から復元できます。)

ファイルシステムからファイルを削除せずに削除対象にするには、git rm --cached foo

おすすめ記事