Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gitignore not working

Tags:

git

gitignore

My .gitignore file isn't working for some reason, and no amount of Googling has been able to fix it. Here is what I have:

*.apk *.ap_ *.dex *.class **/bin/ **/gen/ .gradle/ build/ local.properties **/proguard/ *.log 

It's in the directory master, which is my git repo. I'm running Git 1.8.4.2 because I'm on a MacBook running OSX 10.8.6.

like image 313
user3280133 Avatar asked Aug 21 '14 21:08

user3280133


People also ask

Why git ignore is not working?

Check the file you're ignoring Take a good look at your structure, and make sure you're trying to ignore the file that isn't already committed to your repository. If it is, remove the file from the repository and try again. This should fix the Gitignore not working issue.

Why is Gitignore not working in some files?

Some times, even if you haven't added some files to the repository, git seems to monitor them even after you add them to the . gitignore file. This is a caching issue that can occur and to fix it, you need to clear your cache.

Why is Gitignore not ignoring my files?

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.

Why Gitignore is not working on a folder?

Git cannot ignore that even if you place its name or rule in the . gitignore file. So in essence, Git only ignores untracked files. You should look at your structure (repository) and make sure that the file which you are currently trying to ignore is not added to the repository.


2 Answers

The files/folder in your version control will not just delete themselves just because you added them to the .gitignore. They are already in the repository and you have to remove them. You can just do that with this:

Remember to commit everything you've changed before you do this!

git rm -rf --cached . git add . 

This removes all files from the repository and adds them back (this time respecting the rules in your .gitignore).

like image 161
Ahmad Avatar answered Sep 28 '22 08:09

Ahmad


To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename

To untrack every file that is now in your .gitignore:

First commit any outstanding code changes, and then, run this command:

git rm -r --cached . 

This removes any changed files from the index(staging area), then just run:

git add . 

Commit it:

git commit -m ".gitignore is now working" 
like image 35
Nicolas Avatar answered Sep 28 '22 09:09

Nicolas