When IntelliJ Loses Its Mind, Run This
Occasionally, IntelliJ goes haywire and won't run your project or tests. Next time this happens, close IntelliJ, run the script below in your project directory, and then open IntelliJ and reimport the project.
The script copies your .idea
folder to /tmp
, runs git clean -xdf
to remove all files not checked into git
, and then copies the important files back into a new .idea
folder so you don't lose things like database configurations, dictionaries, and project settings. Your old .idea
folder remains in /tmp
until the next time you run the script or the OS deletes it in case you need something else.
#!/bin/bashif ! git diff-index --quiet HEAD; then echo "Uncommited files detected, commit them and try again. Exiting." exit 1fiset -o errexit -o noclobber -o nounsetidea="./.idea"tmpIdea="/tmp/.idea"items=("$tmpIdea"/codeStyles "$tmpIdea"/dataSources "$tmpIdea"/dictionaries "$tmpIdea"/inspectionProfiles "$tmpIdea"/dataSources*.xml "$tmpIdea"/workspace.xml)rm -rf $tmpIdeamkdir $tmpIdeamv $idea /tmpgit clean -xdfmkdir $ideafor i in ${items[*]}; do if [ -d "$i" ]; then cp -r "$i" $idea; fi if [ -f "$i" ]; then cp "$i" $idea; fidone