I added a bunch of files to be tracked by git, but they were added (and committed) in error. They should be present in the working directory (they're ephemeral files used by my IDE), but not tracked by git. I've now created a .gitignore file and added the appropriate entries, but what is the proper way to remove the files from being tracked by git while leaving them safely in my working directory?
Use the --cached option:
git rm --cached myfile
Complete explanation here: http://www.kernel.org/pub/software/scm/git/docs/git-rm.html
I also like the --dry-run
option. It does not actually change anything, just show what files will be impacted by the real command. It's good to start with that to see what will happen, or to test your file name pattern.
git rm --cached
will remove the files from your index but will keep them in your working directory.
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