Files added to .gitignore are still shown in commit changes

Answered

Hi!
I use Android Studio, and I wanted to use git for my project and I'm very confused now about how version control systems are working here.
So I created a .gitignore file in the project root directory to ignore some files when I'm committing changes. But the problem is when I click commit changes, the opening dialog will contain a  lot of files that I included in .gitignore. 
I've done "git rm --cached ." in the terminal, but nothing changed.
I'm starting to think that if I want to use gui for vcs operations, then I need to declare the ignores in Settings\Version Control\Ignored Files, and I can only use the .gitignore file if I use the terminal for vcs operations. Is it true?

13 comments
Comment actions Permalink

> I need to declare the ignores in Settings\Version Control\Ignored Files, and I can only use the .gitignore file if I use the terminal for vcs operations. Is it true?

No, it is not true. .gitignore is respected. 

However, gitignore affects only unversioned files, and after they are added to git, they cannot be ignored this way. On the screenshot all the files are marked as new - so they are added to git but not yet committed. Check git status - it should list them in the same way.

Just revert the file addition with git reset, or using the Revert action in the IDE, and files should be ignored.

10
Comment actions Permalink

I used git rm -r --cached . many times, with no change. But today I realized what was the problem: once I opened the project with a module's build.gradle file, and IDEA treated that file's directory as the project's root directory, and created the folders here which are needed in a project's root directory, so these files were not ignored, since they were not listed in the project level .gitignore file
To be honest until that I didn't know this happens if I try to open a project with a module's build.gradle file.
I admit it's not a proper way of opening a project, but could you include some warning for this case?

0
Comment actions Permalink

> I admit it's not a proper way of opening a project, but could you include some warning for this case?

You are welcome to submit a request with details at https://youtrack.jetbrains.com/issues/IDEA

0
Comment actions Permalink

Yea, this functionality is totally different that more useful VCS utilities like SourceTree. I have not seen any helpful comments from JB on this. Just 'no this is how it's supposed to work'. So I gave up. 

0
Comment actions Permalink

@Brookeheaton

> this functionality is totally different that more useful VCS utilities like SourceTree

Could you please clarify, what functionality you mean that is totally different?

> I have not seen any helpful comments from JB on this

There are dozens of materials and discussions. Could you please be more specific - what questions or issue do you have unaddressed?

0
Comment actions Permalink

@dmitriy - sure it's fairly straight forward.

So, I have a number of files and directories in my .gitignore file.

If I run 'git status' after adding a single new untracked file, I'll see this change:

Great! That makes total sense.

Now let's take a look at a Git GUI that I've been playing with, GitKraken. I installed GitKraken and added my repo without ANY configuration and out of the box it just. works.

Same thing as git status. I see one new untracked file and no other 'noise'.

Trying to use PhpStorm however - the Default Changelist is simply an unusable mess. What's with all. that. noise? Why does it do that? Even AFTER adding all the directories through PhpStorm's 'ignore' settings - why should I need to do that? Gross. I see that These files are STILL tracked. 27 files?  why? that entire directory is in my .gitignore file. Dumb. So, this is why I don't use PhpStorm for Git management even though I'd like to.

 

3
Comment actions Permalink

The screenshots do not show the full paths to the files, but probably there is just a nested git repository.

Git in the command line works with a single repository and does not show changes from nested or neighbor repositories. The same applies to other GUI git clients - they work with a single repo.

IntelliJ, in contrary, handles all git repositories found in the project. One can control what repositories are monitored for changes in Settings | Version Control - remove mappings of the repos you do not need.

To make it more clear, one can group changes in the Local changes by git root - use the Group By option on the Local changes toolbar.

Also, it might be just a bug - https://youtrack.jetbrains.com/issue/IDEA-148109. 2019.1 will have it fixed. However, judging by the number of modified files, it looks more like a nested git repository.

0
Comment actions Permalink

Same here. I add gitignore file to folder, and PHPstorm show files in changes.

WTF? It's really annoying and it's happing on every project I think. Why PHPstorm doesn't respect the .gitignore file? 

1
Comment actions Permalink

This is likely the mentioned bug. Fixed in 2019.1 - https://youtrack.jetbrains.com/issue/IDEA-148109

Refreshing the Local changes using the Refresh icon on the toolbar should help.

-2
Comment actions Permalink

Looks like as of 2019.2.4, there is now a .idea/.gitignore:

# Default ignored files
/workspace.xml

It must have generated this from when I first created the .gitignore, but ignores future .gitignore additions to ./idea after the first time reading .gitignore.  I wanted to add /webServers.xml to this file to stop it from suggesting to add it at each commit but it had no effect.  I also tried to use File -> Invalidate Caches / Restart but it also had no effect.

JetBrains, please either make sure that any changes to <project_root>/.gitignore will either invalidate this, or stop creating a cache altogether for this which seems more problematic than it's worth.  It's a *GIT* management interface.  There should be no other authority other than .gitignore to look for which files to suggest for a commit.  Any more being "smart" about this just adds negative value to an otherwise excellent interface.

I also see the bug https://youtrack.jetbrains.com/issue/IDEA-148109 returns a 404 now.  I'll be filing a new bug if I can't find any other reference to this issue in the bug tracker.

0
Comment actions Permalink

> but ignores future .gitignore additions to ./idea after the first time reading .gitignore.

IDEA uses this gitinore to ignore only these files we do not recommend sharing. This includes workspace.xml, shelf, database connections. 

/webServers.xml is not the file that is not recommended for sharing.

 

> I wanted to add /webServers.xml to this file to stop it from suggesting to add it at each commit but it had no effect

 

> or stop creating a cache altogether for this which seems more problematic than it's worth

There is no cache. Changes to the .gitingore (when it is saved on disk so git knows its content) are reflected in the IDE.

 

> There should be no other authority other than .gitignore

And it is exactly how it works. All ignored info is got from git (using git status and other respective commands)

 

> I also see the bug https://youtrack.jetbrains.com/issue/IDEA-148109 returns a 404 now

That's because the URL includes the dot for some reason. The issue is there and accessible via the correct URL.

This request is about a different thing though. It is about providing proper highlighting for gitignored files. 

 

> I'll be filing a new bug if I can't find any other reference to this issue in the bug tracker.

Please do so, with exact steps to reproduce (or better a sample project) and logs, if you see that files ignored by gi in the command line are not ignored in the IDE.

0
Comment actions Permalink

I'm still seeing the wrong colours showing.  I haven't checked a file into git previously but it is showing up in the stashed colour.

1
Comment actions Permalink

Atreeonhill
If your file marked green or blue - it means that the file has been added to git so you need to remove it from there with `git rm --cached <filename>`

0

Please sign in to leave a comment.