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?
Please sign in to leave a comment.
Hi,
What exactly is broken? Please provide details.
> 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.
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?
> 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
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.
@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?
@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.
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.
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?
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.
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.
> 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.
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.
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>`
This will work for me .
Step 01
Go to the project folder and run
git rm -r --cached
Step 02
Then Run
git reset
Step 03
Right-click folder > Delete
Step 04
File > Edit > Undo Deleting Directory
That's all
Any chance to fix this dumb behavior by 2030?
1. Add folder into .gitignore file.
2. Add folder which supposed to keep generated files you need to exclude from git and put a new file into this folder.
3. No effect, new file is in staging area. Ok.
4. Check if git sees ignore rule via “git check-ignore -v “path to file you need to ignore””. It does.
5. Reset cache using “git rm -r --cached “path to folder with files””. Ok, now file in “Unversioned”. Commit.
6. Generate new file in this folder. It's in staging again.
7. Move your folder with file into bin filder of your project. Files disappeared from IDE git window as you expect it to be on step 1.
IDE does ignore new folders in .gitignore.
Aleks
I cannot reproduce it. Adding a file that it is ignored in .gitignore will make it ignored automatically.
Where is your .gitignore file located? Is it in the root of the project?
How do you define the folder thart you are ignoring?
The only reliable way to deal with the Jetbrains bug is to fix it through the git command line interface.
1. Discard or stash local changes to ensure a clean working directory:
- To discard all changes and untracked files:
git reset --hard
git clean -fdx
- To stash changes temporarily (including untracked files):
git stash --include-untracked
2. Pull the latest changes from the remote repository:
git pull
3. Update the `.gitignore` file to exclude unnecessary files. For example, include the following patterns:
cmake-build-*/
.idea/
*.log
*.yaml
*.cmake
*.o
*.o.d
After updating the `.gitignore`, commit and push it:
git add .gitignore
git commit -m "Update .gitignore to exclude unwanted files"
git push
4. On other hosts, pull the latest changes and clean the local working directory:
- Pull the latest changes:
git pull
- Remove any remaining junk files:
git clean -fdx
5. Verify that the project compiles and runs successfully. If necessary, regenerate the build files and rebuild the project:
cmake . && make
To prevent similar issues in the future:
- Ensure `.gitignore` excludes all temporary and build files, IDE-related directories, and logs.
- Periodically clean untracked files and directories across all hosts:
git clean -fdx
- Share best practices with team members (including explaining Jetbrains bugs), such as respecting the `.gitignore` file and avoiding unnecessary file commits.
Sorry, No, I am saying it is working fine when tested.
Can you please elaborate what is wrong and how to reproduce?
deleting the folder or file with problems and going to local history and reverting the change worked for me, ive had this problem for over a year
Paumarzov
This is because when deleting via IDE UI, these files are removed from the git index, re-adding them via local history will make .gitignore to take effect.
I have the same issue. It happened once before. But often also works…. Strange.
What happened this time:
- I have a project with a folder in .gitignore. All good.
- I added a component via composer. This created a folder within the ignored folder.
- Now this new content shows up in PhpStorm in the Commit window as Unversioned Files.
I cant get rid of them… Git in CLI says ‘nothing to commit, working tree clean’
Mathis Koblin
Does the added component have its own git repository (
.gitfolder)?Ivan Pajic No, it hasn't. Even after removing most of its files, the issue persists. I also tried closing and reopening the project and the IDE.
Mathis Koblin
Thanks. Could you please submit a ticket at: https://intellij-support.jetbrains.com/hc/en-us/requests/new?ticket_form_id=66731 and share additional information like screen recording, IDE logs (Help > Collect Logs and Diagnostic Data),
.gitignorefile contents. Thank you!