Say I have a file in my git repostiory called foo
.
Suppose it has been deleted with rm
(not git rm
). Then git status will show:
Changes not staged for commit:
deleted: foo
How do I stage this individual file deletion?
If I try:
git add foo
It says:
'foo' did not match any files.
Since Git 2.0.0,
git add
will also stage file deletions.Git 2.0.0 Docs - git-add
to Add all ready deleted files
thank check to make sure
you should be good to go
Use
git rm foo
to stage the file for deletion. (This will also delete the file from the file system, if it hadn't been previously deleted. It can, of course, be restored from git, since it was previously checked in.)To stage the file for deletion without deleting it from the file system, use
git rm --cached foo
You can use
git rm -r --cached -- "path/to/directory"
to stage a deleted directory.
You could do
git add -u
.This would help if you want to delete multiple files, without doing
git rm
for each of them.To stage all manually deleted files you can use:
To add an alias to this command as
git rm-deleted
, run: