42

I'm using IntelliJ IDEA Community Edition 2016.1. I've put my project under Git, hosted it on GitHub.

When I first hit that Share Project on GitHub button, every single file was selected to be put under version control.

Now I want to exclude the module IML file from version control. Obliviously, I want to keep it on my hard disk. Unfortunately, I cannot find a way to do this. How do I achieve this?

I tried to delete it from the web interface, but I'm getting some fatal errors while pulling/pushing.

0

3 Answers 3

71

There is a little trick.

  • Go to File Menu-> Settings | Version Control | Confirmation, then check the Show options before adding to version control setting under the When files are created section. Alternatively, you could check Do not add. It is mandatory that you do not check Add silently.
  • Delete the file you don't want to be tracked by VCS.
  • Press Ctrl + Z to undo the removal of the file. If IDE shows a popup window which lets you choose whether or not to add the new file to VCS, click No.
  • Commit your local changes, and the files are removed from VCS.
2
  • 3
    This is exactly what i needed. If i undeleted and then tried commit and push got an error. Instead, delete, commit and push, then, with cursor on the package name, undelete but don't add to vc. works great
    – Slayer6
    Feb 17, 2018 at 17:16
  • 4
    IMPORTANT - step delete the files must be done in "Version Control Window" (Alt+9), tab local changes. If you delete files in project tree, there is no ctrl+z to get your files back.
    – Miro
    May 21, 2019 at 12:20
35

Once you commit the file it will begin to be tracked.
In order to remove the file from this point you have to remove them from the repository.

What you need to do now is to delete the entire .idea folder, commit the deletion, add the idea extension to your .gitignore file.


Explaining how to do from command line, can be done via IDEA as well.

# Remove the file from the repository
git rm --cached .idea/

# now update your gitignore file to ignore this folder
echo '.idea' >> .gitignore

# add the .gitignore file
git add .gitignore

git commit -m "Removed .idea files"
git push origin <branch>
4
  • How do I access Git Bash from inside IntelliJ IDEA?
    – spongebob
    Mar 22, 2016 at 20:01
  • 1
    View - Tool Windows - Terminal will open an embedded bash.
    – Jelle
    Mar 22, 2016 at 20:06
  • 1
    What you have to remember is this: remove the files and commit the remove and at the same time add it to the ignore file
    – CodeWizard
    Mar 22, 2016 at 20:10
  • Hi , what is the harmful of that if we have .idea in remote repository? May 17, 2020 at 8:11
0

for subversion:

  • go to file properties context menu > copy path
  • open terminal use "svn rm --keep-local" to remove

    svn rm --keep-local /aa/bb/cc/myfile.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.