0 votes
1 view
in DevOps and Agile by (30k points)

Say I have a file in my git repository called foo.

Suppose it has been deleted with rm (not git rm). Then git status will show:

Changes are 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.

1 Answer

0 votes
by (51.2k points)

For this question, you can use:

git rm foo 

This is used to stage the file for deletion. 

This will delete the file from the file system. and restore it from git.

And to stage the file for deletion (without deleting it from the file system), use:

 git rm --cached foo

Reference: https://git-scm.com/docs/git-rm#Documentation/git-rm.txt---cached

Welcome to Intellipaat Community. Get your technical queries answered by top developers !