i\'m adding this to .gitignore file
.idea/*
but anyway the status is:
# modified: .gitignore
#
Git add .
Git status //Check file that being modified
// git reset HEAD --- replace to which file you want to ignore
git reset HEAD .idea/ <-- Those who wanted to exclude .idea from before commit // git check status and the idea file will be gone, and you're ready to go!
git commit -m ''
git push
To the people who might be searching for this issue still, are looking at this page only.
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'
Here is a little bit more info.
- This command will remove all cached files from index.
- This command will add all files except those which are mentioned in
gitignore
.- This command will commit your files again and remove the files you want git to ignore, but keep them in your local directory.
Simply add git rm -r --cached <folder_name/file_name>
Sometimes, you update the .gitignore file after the commit command of files. So, the files get cached in the memory. To remove the cached files, use the above command.
The solutions offered here and in other places didn't work for me, so I'll add to the discussion for future readers. I admittedly don't fully understand the procedure yet, but have finally solved my (similar) problem and want to share.
I had accidentally cached some doc-directories with several hundred files when working with git in IntelliJ IDEA on Windows 10, and after adding them to .gitignore
(and PROBABLY moving them around a bit) I couldn't get them removed from the Default Changelist.
I first commited the actual changes I had made, then went about solving this - took me far too long.
I tried git rm -r --cached .
but would always get path-spec
ERRORS, with different variations of the path-spec
as well as with the -f
and -r
flags.
git status
would still show the filenames, so I tried using some of those verbatim with git rm -cached
, but no luck.
Stashing and unstashing the changes seemed to work, but they got queued again after a time (I'm a bity hazy on the exact timeframe).
I have finally removed these entries for good using
git reset
I assume this is only a GOOD IDEA when you have no changes staged/cached that you actually want to commit.
Your .gitignore
is working, but it still tracks the files because they were already in the index.
To stop this you have to do : git rm -r --cached .idea/
When you commit the .idea/
directory will be removed from your git repository and the following commits will ignore the .idea/
directory.
PS: You could use .idea/
instead of .idea/*
to ignore a directory. You can find more info about the patterns on the .gitignore man page.
Helpful quote from the git-rm
man page
--cached
Use this option to unstage and remove paths only from the index.
Working tree files, whether modified or not, will be left alone.