When submitting code using IDEA, you may encounter folders that you want to ignore appearing in the submit list.

Take the.idea directory as an example. If the.idea directory was not added to the.gitignore file and the.idea directory was submitted to the.gitignore file, then adding.idea directory to the.gitignore file will not make the.idea directory in the commit list go away. At this point we need to use the command to delete the.idea directory in the staging area.

Git rm –cached

This command deletes files directly from the staging area, leaving the workspace unchanged. Git rm –cached “is better than “git reset head”, which deletes the cached version and replaces it.

Git rm -r –cached

deletes files and folders

Git rm -r -- Path to the cached file or folderCopy the code

For example,

git rm -r --cached .idea/
Copy the code

Refer to the article

Intellij creates a file and automatically adds it to Git

Gitignore configuration rule and git rm -r –cached Remove files already hosted on Git