How can I remove a file from Git within IntelliJ VCS?
In the terminal, use git rm --cached -r .idea/
.
This will remove the files from the GIT index, but leave the files locally.
To change a file from green (staged) to red (untracked) using Intellij:
- Right click the file(s)
- Hover over
Git
(the git pane will expand) - Click
Rollback...
(in older versionsRevert
) - Check that
Delete local copies of added files
is not checked and click theRollback
button
This will not delete the file, only unstage it (remove it from git's index).
Given your project is linked to a git repo already, you can just use the standard IntelliJ feature to "delete" the file.
In the project pane, focus the file and hit Delete
key. The "Safe Delete" popup will appear, click OK
.
Now observe under 9: Version Control
-> Local Changes
that the file is listed there in "grey" - when you commit and push to your git
repo, the file will be deleted on the current branch.
Edit: if these are IntelliJ files, this becomes more difficult.
First, close IntelliJ, make a list of the exact files you want to delete from repo, and take a copy of those files on your local file system.
Then use git rm to remove them and then commit.
Next step, add a .gitignore
file to ignore local IntelliJ files. A good start is *.iml
and .idea
.
Finally, restore the files that you copied up and restart IntelliJ.