6

I am new to Git and I am using it to backup an iPhone project I am working on. I have added a list of files that Git should ignore (xcode files) when I update, but this .perspectivev3 (which is in my .gitignore) file keeps showing up when I go to commit my changes. Does anyone know why this is, or what I am doing wrong?

Thanks,

Zach

This is what is in my .gitignore file:

# xcode noise
*.mode1v3
*.pbxuser
*.perspective 
*.perspectivev3
*.pyc 
*~.nib/
build/*

# Textmate - if you build your xcode projects with it
*.tm_build_errors

# old skool
.svn

# osx noise
.DS_Store
profile
ab217
  • 16,900
  • 25
  • 74
  • 92
  • What do you mean "go to commit my changes"? Non-ignored non-added files only show up with "git status" and such – jA_cOp Jul 21 '10 at 06:26
  • 1
    It may be a dumb question, but have you ever committed .perspectivev3 previously or added it to the index before you updated your gitignore file? – CB Bailey Jul 21 '10 at 06:28

3 Answers3

10

If it keep showing up in the git status, it must have been added or committed before.

You need to

  • git rm --cached that file, in order for the git status to not list it anymore (it is was just added, but not committed yet).
  • git rm that file, if it was previously committed (see this question for instance)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
9

You can use

$ git rm --cached ./whatever1.txt

after something is already under version control.

In fact, if you have "whatever1.txt" under version control and you want to remove it from git, but leave your working tree undisturbed, then just do this:

$ git rm --cached ./whatever1.txt
$ echo /whatever1.txt >> ${PROJECT_ROOT}/.gitignore
$ git status   # this will now show ./whatever1 as "deleted" (from git, not your working tree, and will show gitignore as modified or created)
$ git commit -a

And that's it.

Only use

$ git rm

when you want to remove the file from both the working tree AND the git repo.

CAVEAT: The likely scenario you would use this is for removing IDE-specific files from git. In this example "whatever1" represents your IDE file(s) you're removing. If you are working on a project with several people and you push this changeset to a shared repo, then their "./whatever1" files WILL BE DELETED when they pull this changeset. The easy thing to do from here for the people on the receiving end is:

$ git checkout 1215ef -- ./file-you-want-to-restore ./another-file ./another-etc

(where 1215ef represents the last commit before the deletion)

This has the effect of restoring those files that were present at their last commit before the pull. After they have done this those files will be safe and not show up as uncommitted b/c they will fall under the exclusion of gitignore.

Good luck!

jpswain
  • 14,642
  • 8
  • 58
  • 63
3

.gitignore only applies for untracked files. If you've git-add'ed files that are otherwise untracked due to .gitignore, they will still be part of the repository.

Simply remove the files from the repository you don't want anymore:

git rm *.perspectivev3
jA_cOp
  • 3,275
  • 19
  • 15
  • 1
    Hey, I did add that pesky file before I added it to the ignore file. I removed the file, and when I tried to commit a change, the file was not longer there, so your advice worked. Thanks guys. – ab217 Jul 21 '10 at 08:19
  • @Zach Banks I'd now mark one of these answers as accepted, so they get the credit and other users know the question is solved. – Edd Jul 21 '10 at 11:03