git rm --cached [filenames]
Here’s how I removed all the files I wanted to delete from one of my bin subdirectories:
git rm --cached bin/com/devdaily/sarah/\*
I use the unusual * syntax at the end of that command instead of * because you need to escape the * from the git command. In a simpler example, if there was just one file in the bin directory named Foo.class that I wanted to remove from the Git repository, I would use this command:
git rm --cached bin/Foo.class
To be clear, what this command means is: You want to keep these files on your hard drive, but you don’t want Git to track them any more.
Stage all (new, modified, deleted) files
git add -A
Stage all (new, modified, deleted) files in current folder
git add .
Stage new and modified files only
git add --ignore-removal .
Stage modified and deleted files only
git add -u
If you want to remove the file from the Git repository and the filesystem, use:
git rm file1.txt
git commit -m "remove file1.txt"
But if you want to remove the file only from the Git repository and not remove it from the filesystem, use:
git rm --cached file1.txt
git commit -m "remove file1.txt"
This will help you remove cached index files, and then only add the ones you need, including changes to your .gitignore file.
1. git rm -r --cached .
2. git add .
3. git commit -m 'Removing ignored files'