Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using IntelliJ IDEA ignoring unversioned files aren't added to .gitignore

I just noticed that when I have unversioned files or whole directories in IDEA, if I specify to have those files or directories ignored by right clicking and selecting ignore, they're not added to .gitignore.

How does IDEA manage that list then? It seems to recognize changes to .gitignore, so why not add ignored files to .gitignore too? I'm just thinking if someone forks my repo, or I start working with another developer, they'll potentially push files that I asked IDEA to ignore.

Thanks.

like image 407
Patrick Grimard Avatar asked Jul 24 '13 23:07

Patrick Grimard


People also ask

How do I ignore Unversioned files in IntelliJ?

IntelliJ, however, adds its own mechanism to ignore files:Window "Version Control", Tab "Local Changes", Button "Configure Ignored Files" (on the left). IntelliJ simply never performs a "git add" for files ignored in that way. Note that this is NOT the same as Git's "gitignore".

Why is my file not being ignored in Gitignore?

. gitignore only ignores files that are not part of the repository yet. If you already git add ed some files, their changes will still be tracked. To remove those files from your repository (but not from your file system) use git rm --cached on them.

How do I add ignored files in IntelliJ?

In project view dialog, right click on any file / directory to add that file or directory to . gitignore for the project. If a . gitignore file does not exist for the project, it will be created.


1 Answers

Git has its standard mechanisms to ignore files, basically:

  • Patterns read from a .gitignore file in the same directory or in any parent directory.
  • Patterns read from $GIT_DIR/info/exclude.
  • Patterns read from the file specified by the configuration variable "core.excludesFile".

IntelliJ, however, adds its own mechanism to ignore files:

Window "Version Control", Tab "Local Changes", Button "Configure Ignored Files" (on the left). IntelliJ simply never performs a "git add" for files ignored in that way. Note that this is NOT the same as Git's "gitignore". The effect inside IntelliJ is the same, but it is not very transparent what is going on - as mentioned in the IDEA issue linked in the comment by CrazyCoder.

On the Git command line a "git status" will show the "IntelliJ-ignored files" as "Untracked files" (use "git add ..."). If they are directories, "git status" will not even mention files contained in them because the directory is already "untracked".

Properly "Git-ignored" files do not show at all with "git status", i.e. no suggestion to use "git add ...".

The best strategy probably is to never use IntelliJ's ignore mechanism and to rely on Git's gitignore alone. For a Maven project in IntelliJ I am currently using these lines in a private gitignore file pointed at by the Git configuration variable "core.excludesfile":

/.idea/
target/
like image 93
StaticNoiseLog Avatar answered Oct 10 '22 09:10

StaticNoiseLog