Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitignore just doesn't work. I can't get it to ignore .DS_Store & .gitignore files

Tags:

git

I have .gitignored .DS_Store and .gitignore files. But still see them in the "git status".

Can someone explain to me how I can make sure that the files that I am trying to ignore don't show up while checking status?

git status

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   .DS_Store
#   .gitignore

I have the .DS_Store file in all the subfolders of my repository. So I want all of those to be ignored. What should I do?

I have configured .gitignore file in the root directory of my repository. Should I copy this to all the subfolders for git to ignore these files? Is adding .gitignore in .gitignore file not acceptable?

EDIT: Jan 21st 2014 ==================

I still can't figure this out. The comments below didn't really help me. So I am reposting my query.

Below is a snippet of my git status output. The actually output spans couple of pages. And all the files in this output are files/folders I don't want in my repo. These are untracked files so I have never git added them. But when I create a new project, I have to search for the related files/folders in this huge list before adding them, which is making the whole process a bit irritating.

# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   ../../.DS_Store
#   ../../Classes/
#   ../.DS_Store
#   ../Basics/.DS_Store
#   ../adt/.metadata/
#   ../adt/Fundamentals/.classpath
#   ../adt/Fundamentals/.project
#   ../adt/Fundamentals/.settings/
#   ../adt/Fundamentals/bin/
#   .DS_Store
#   .metadata/

Below is my .gitignore file. Can someone please point out my mistake?

*.class
*.pyc                                                                           
colors                                                                          
**/.DS_Store                                                                    

# Mobile Tools for Java (J2ME)                                                  
.mtj.tmp/                                                                       

# Package Files #                                                               
*.jar                                                                           
*.war                                                                           
*.ear                                                                           

#Eclipse files                                                                  
.project                                                                        

# folders                                                                       
.classpath/                                                                     
.settings/                                                                      
.metadata/                                                                      
WEB-INF/lib/                                                                    
META-INF/                                                                       
Servers/ 

# Byte-compiled / optimized / DLL files                                         
__pycache__/                                                                    
*.py[cod]                                                                       

# C extensions                                                                  
*.so                                                                            

# Distribution / packaging                                                      
bin/                                                                            
build/                                                                          
develop-eggs/                                                                   
dist/                                                                           
eggs/                                                                           
lib/                                                                            
lib64/                                                                          
parts/   
like image 290
deepng Avatar asked Jan 10 '14 11:01

deepng


People also ask

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.

Should you add .DS_Store to Gitignore?

DS_Store file in your directories. It's not a big issue, but often you need to exclude these files explicitly in your . gitignore file, to prevent any unnecessary files in your commit. You may want to ignore this file globally, so next time you don't need to add it to your project's ignore list.

Why is Gitignore file not working?

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.


2 Answers

  1. You shouldn't ignore your .gitignore. I don't think the ignore feature works when you don't have it in your repository. I'm not sure though.
  2. Files that are already tracked won't be ignored, even if you add them to .gitignore. If you want them to be ignored after they've been added to the repository already, you have to remove them with git rm filename first.
like image 137
FSMaxB Avatar answered Oct 23 '22 07:10

FSMaxB


If you want to ignore a change to a file that is tracked by git you can specify to git that it should assume that the file has not changed:

git update-index --assume-unchanged file

and to start tracking changes again do:

git update-index --no-assume-unchanged file

if you have already added a file that should be completely ignored (.gitignore) you have to git rm it first.

reference: https://www.kernel.org/pub/software/scm/git/docs/git-update-index.html
source: http://blog.pagebakers.nl/2009/01/29/git-ignoring-changes-in-tracked-files/

like image 45
gauteh Avatar answered Oct 23 '22 08:10

gauteh