Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accidentally committed .idea directory files into git

Tags:

git

I have accidentally committed the .idea/ directory into git. This is causing conflicts everywhere else I need to checkout my repo. I was wondering how do I remove these files from the remote?

I still need these files locally since the Intellij IDE needs them. I just don't want them in the remote. I have added the directory .idea/ to my .gitignore and committed and pushed this file into remote. This seems to have no effect during my checkout on my other machine though. I still get the error message:

error: The following untracked working tree files would be overwritten by checkout: .idea/.name .idea/compiler.xml .idea/copyright/profiles_settings.xml .idea/encodings.xml .idea/misc.xml .idea/modules.xml .idea/scopes/scope_settings.xml .idea/uiDesigner.xml .idea/vcs.xml .idea/workspace.xml 
like image 747
sethu Avatar asked Jun 20 '12 16:06

sethu


People also ask

Should I git ignore .idea folder?

Yes, but if you want to ignore all of the . idea files you only need to add /. idea/ to your . gitignore file once and forget about it.

Should I commit .idea files to Git?

You shouldn't ignore the idea folder. you're supposed to commit almost all of it to the repo.


1 Answers

Add .idea directory to the list of ignored files

First, add it to .gitignore, so it is not accidentally committed by you (or someone else) again:

.idea 

Remove it from repository

Second, remove the directory only from the repository, but do not delete it locally. To achieve that, do what is listed here:

Remove a file from a Git repository without deleting it from the local filesystem

Send the change to others

Third, commit the .gitignore file and the removal of .idea from the repository. After that push it to the remote(s).

Summary

The full process would look like this:

$ echo '.idea' >> .gitignore $ git rm -r --cached .idea $ git add .gitignore $ git commit -m '(some message stating you added .idea to ignored entries)' $ git push 

(optionally you can replace last line with git push some_remote, where some_remote is the name of the remote you want to push to)

like image 115
Tadeck Avatar answered Sep 28 '22 03:09

Tadeck