[Ruby] I want to delete files managed by Git

less than 1 minute read

When I forget to write it in .gitignore and commit it, “Adding to .gitignore is all right…” Do you misunderstand that? Like me.. sweat

The files already managed by Git will not be removed simply by adding it to .gitignore later, so I will write a countermeasure for such a case.

If you want to keep the files managed by Git and exclude them

$ git rm --cached [filenames to exclude]

After that, be sure to add the file you want to exclude to .gitignore. Notes: Be sure to add --cached! !! If not attached, the files will be deleted.

If you want to delete each file

$ git rm [filename you want to delete]

If you want to delete each directory

$ git rm -r [directory to delete]

Finally

When I started using Git, I forgot a few times and committed it, and I checked it each time, so I will leave it as a memorandum.

I hope it will be useful for those who have the same circumstances.