Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore does not ignore one folder

Tags:

git

gitignore

I've got the following in my .gitignore:

#built application files
*.apk
*.ap_
# files for the dex VM
*.dex
# Java class files
*.class
# generated files
bin/
gen/
# Local configuration file (sdk path, etc)
local.properties
# Windows thumbnail db
Thumbs.db
# OSX files
.DS_Store
# Eclipse project files
.classpath
.project
# Android Studio
.idea
build/
cache.properties.lock
.idea/workspace.xml
*.iws
.gradle/
**/.gradle/

However, whenever I make changes to my app, git includes files like .gradle/1.12/taskArtifacts/cache.properties.lock to the commit.

What's wrong here? Why does it work with the folder build/ but not with .gradle/?

like image 432
Johann Bauer Avatar asked Jul 21 '14 21:07

Johann Bauer


People also ask

Can Gitignore ignore folders?

gitignore is a plain text file in which each line contains a pattern for files or directories to ignore. It uses globbing patterns to match filenames with wildcard characters. If you have files or directories containing a wildcard pattern, you can use a single backslash ( \ ) to escape the character.

Why is my file not being ignored in Gitignore?

gitignore ignores only untracked files. Your files are marked as modified - meaning they were committed in the past, and git now tracks them. To ignore them, you first need to delete them, git rm them, commit and then ignore them.

How do I Gitignore a folder?

If you want to ignore a file that you've committed in the past, you'll need to delete the file from your repository and then add a . gitignore rule for it. Using the --cached option with git rm means that the file will be deleted from your repository, but will remain in your working directory as an ignored file.

Does Gitignore need to be in every folder?

A . gitignore file is a plain text file where each line contains a pattern for files/directories to ignore. Generally, this is placed in the root folder of the repository, and that's what I recommend. However, you can put it in any folder in the repository and you can also have multiple .


2 Answers

It is possible that Git is already tracking these files. Running the following command in terminal worked for me for both .gradle and .idea files:

git rm --cached .gradle -r
like image 56
Farhan Avatar answered Oct 06 '22 01:10

Farhan


This is common for dot(.) that are not included, add this to .gitignore

.*
!/.gitignore
like image 27
klerk Avatar answered Oct 06 '22 01:10

klerk