16

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/   
deepng
  • 809
  • 2
  • 9
  • 20
  • 2
    Could you post your .gitignore file. Could you also `git add .gitignore` – Martin Owen Jan 10 '14 at 11:30
  • I would avoid putting `.gitignore` into an ignore file. This file is meant to be part of the repository. For local ignores, the `.git/info/exclude` file does much the same thing, but is *not* included in the repository. Shared ignores into `.gitignore`, personal ones into `.git/info/exclude`. – ChrisGPT was on strike Jan 10 '14 at 13:33

10 Answers10

26
  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.
Pieter
  • 31,619
  • 76
  • 167
  • 242
FSMaxB
  • 2,280
  • 3
  • 22
  • 41
8

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/

gauteh
  • 16,435
  • 4
  • 30
  • 34
5

I had an issue getting .DS_Store ignored where the problem was that it had already been committed to the repo. Removing it resolved the issue.

$ git rm --cached .DS_Store
Ben Thielker
  • 4,104
  • 4
  • 21
  • 20
4

This is what your .gitignore should look like:

.DS_Store

Also, the .gitignore is meant to be tracked, ignoring it doesn't make sense. So after you've updated the file to contain just .DS_Store do:

$ git add .gitignore
$ git commit -m "Track .gitignore"
Agis
  • 32,639
  • 3
  • 73
  • 81
  • 1
    If `.gitignore` is committed, there is no need to have `.gitignore` written in `.gitignore` itself, because it will no longer an untracked file. – lrineau Jan 10 '14 at 12:01
  • Well '.DS_Store' is untracked file in my case. I have such a long list of untracked files that I have to scroll up couple of times to get to the tracked part. How can I get rid of these Untracked files? Does adding them in .gitignore, make sure that I don't see them when I hit 'git status'? – deepng Jan 13 '14 at 14:02
  • @deepng ok there's no need for the last 2 lines then. Updated my code. – Agis Jan 13 '14 at 14:04
  • @Agis, doesn't adding files to `.gitignore` make sure that I don't see them in the Untracked files list? – deepng Jan 13 '14 at 14:12
  • @deepng yes it does. But it's also a good practice to track the `.gitignore` file itself since you propably want to ignore these files everywere (ie. other members working on it). – Agis Jan 13 '14 at 14:16
  • @deepng Do you mind telling me why you unaccepted the answer? I could elaborate more if you still have a problem. – Agis Jan 22 '14 at 07:55
1

Add the lines

 **/.DS_Store
 **/.gitignore
Hogan
  • 69,564
  • 10
  • 76
  • 117
1

Why you’re ignoring .gitignore? This doesn’t make a sense. If you want to ignore some files just locally (i.e. don’t track and publish this setting to the remote repository), then use .git/info/exclude instead. Just add .DS_Store to it, that’s all.

Jakub Jirutka
  • 10,269
  • 4
  • 42
  • 35
1

I faced the same problem. None of the .gitignore lines were in effect.

I converted the file encoding into UTF-8 and it worked instantly.

0

I experience the same issue. The solution is to add a .gitignore under your home directory first.

My end the repository .gitignore no longer appears in indexing tracking.

0

This is building off of Jakub Jirutka's response. I was a little confused upon first glance, but I tried it and it worked. Here is his answer stated - hopefully - more clearly.

His answer put simply: store unwanted files in .git/info/exclude (which is inside every git repository). Put each on a new line.

The .gitignore file is useful to help ignore files and directories that you know are or will be generated but are unwanted. The fact that you can git add .gitignore and then commit that and push it is really useful. When you clone this repository on another computer, for example, all of the files that should be ignored (after a ./configure; make; sudo make install;, for example, usually generates example files and a lot of other links) will be ignored (if they are in the .gitignore.

However, sometimes, one is not sure whether a file is wanted in the repository or wants the file to just exist outside of git control as if it were in a non-git-controlled directory. This can be done by adding this to the exclude file inside of the exclude file inside the .git/info directory.

Every git repository has a .git folder. To completely exclude a file or directory, go to the good ole terminal, cd to the root of the repository (i.e. cd src/best_repo_eva). Then you will see a .git/. Then, cd .git/info/. There will probably only be one file there called exclude. Use your favorite editor (just kidding; you may only use butterflies' wings to focus cosmic rays in the upper atmosphere to flip the correct bits in your drive platter ;) to edit the exclude such that it contains the files you want to exclude on new lines.

Easier solution: You have two files you want excluded: tmp1 and ignoreadf

Go to terminal and...

  • cd src/best_repo_eva
  • echo -e "tmptab\n igntab" >> .git/info/exclude

The tabs, obviously, only work if your terminal supports it. Note the -e (supports backslash escapes) and the \n (which is emphasized with a space) between the the two files.

Storing a lot of files with a similar ending, could be as easy as cd src/best_repo_eva then echo -e $(ls -1 | grep "tmp") >> .git/info/exclude (that's ls -ONE not ls -L - note that ls -a -1 doesn't work, unfortunately). That would store all files that contain the sequence "tmp" into the exclude file.

dylnmc
  • 3,810
  • 4
  • 26
  • 42
0

I had the same exact issue on Mac OS X. I had .gitignore file in the repo but it just won't work.

What was weird when I wanted to print the .gitignore content to the console with the cat command it printed as it was empty. When opened with vim it appeared as normal.

The solution was to remove the file, create a new one and put the content into it again. After that, ignoring files started to work and when I done cat .gitignore it printed properly.

Lukasz Korzybski
  • 6,689
  • 2
  • 27
  • 27