How can I remove deleted files from my Git repo?
I've deleted a folder of a JavaScript library, which contained many files. I then went to commit the changes like so:
git add . git commit "message" git status
But it shows all those files as "deleted ....".
How can I make them go away?
Delete Files using git rm. The easiest way to delete a file in your Git repository is to execute the “git rm” command and to specify the file to be deleted. Note that by using the “git rm” command, the file will also be deleted from the filesystem.
Listing all the deleted files in all of git history can be done by combining git log with --diff-filter . The log gives you lots of options to show different bits of information about the commit that happened at that point.
To add a single file to the commit that you've deleted, you can do git add what/the/path/to/the/file/used/to/be . This is helpful when you have one or two deletions to add, but doesn't add a batch of deletions in one command.
This will add deletes as well.
git add -u .
Check what's staged to be committed with:
git status
If it lists the files under the "to be committed" section, then just proceed with the commit; the files will remain deleted. (Git tracks deletions too, not just changes.)
If it lists the files under the "changed but not updated" section, then you have two options:
git checkout path/to/folder
git rm -r path/to/folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With