Patrick Grimard
Patrick Grimard

Reputation: 7126

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.

Upvotes: 7

Views: 10797

Answers (2)

Stefano G.
Stefano G.

Reputation: 309

to obtain that PYCharm ignore files in project's dirs that are in .gitignore, You must set the dirs without the ./ in the head Es. from:

./.idea/
./chromedriver_win32/
./dist/
./files/
./mdc_venv/

to

.idea/
chromedriver_win32/
dist/
files/
mdc-venv/

Upvotes: 0

StaticNoiseLog
StaticNoiseLog

Reputation: 1400

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/

Upvotes: 6

Related Questions