tags:

views:

57

answers:

6

Hi all,

I started using git with an xcode project and have recently discovered that I can use .gitignore and .gitattributes files to ignore the noise from the compiler and system. Now that I have the .gitignore and .gitattributes files in place, how can I "apply" the new ignore rules and get rid of the crud from version control?

My .gitignore file is:

# xcode noise
*.modelv3
*.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

And my .gitattributes file is:

*.pbxproj -crlf -diff -merge

Thanks!

A: 

You shouldn't have to 'apply' the changes. simply put the .gitignore file in your home directory (if you want it to be global) or in your project root (if you want it to be unique only to that project).

Edit: It occurs to me that you might be having this problem because you've added the files you don't want to track already. Here's what the gitignore man page has to say about that:

Note that all the gitignore files really concern only files that are not already tracked by git; in order to ignore uncommitted changes in already tracked files, please refer to the git update-index --assume-unchanged documentation.

Alex Bliskovsky
A: 

If you are already tracking files you want to ignore, you have to remove them with

git rm --cached <file>

Git won't ignore files which are already tracked (i.e. you added them with git add ).

Sven Koschnicke
A: 

mv the_file_i_want_to_ignore the_file_i_want_to_ignore.back

git rm the_file_i_want_to_ignore

mv the_file_i_want_to_ignore.back the_file_i_want_to_ignore

git status

git commit -m 'ignore a bunch of stuff i should have ignored before'

this a bit of a manual workflow but its how i've done this in the past.

Jed Schneider
You really want to use `git rm --cached`.
jleedev
+4  A: 

use git rm --cached for files and git rm -r --cached for the build/ directory

Neal L
A: 

If you want to remove the files completely, then here's a handy reference from Github.

Be warned that:

  1. This will rewrite your history, so it's probably only worth doing before you publish your repo.
  2. Remember that the old shas will still be in the object database, but the guide I've linked to will show you how to deal with those as well.
Abizern
A: 

Here is one way to “untrack” any files that are would otherwise be ignored under the current set of exclude patterns:

(GIT_INDEX_FILE=some-non-existant-file \
 git ls-files --exclude-standard --others --directory --ignored -z) |
xargs -0 git rm --cached -r --ignore-unmatch --

This leaves the files in your working directory but removes them from the index.

The trick is to use git ls-files with a non-existent index so that it thinks there are no tracked files. The shell code above asks for all the files that would be ignored if the index was empty and then removes them from the actual index with git rm.

After the files are “untrack”ed, use git status to verify that nothing important has been “untracked” (if so adjust your exclude patterns and use git reset -- path to restore the removed index entry) and make a new commit that leaves out the “crud”.

The “crud” will still be in the old commits. You can use git filter-branch to produce clean versions of the old commits if you really need a clean history (n.b. using git filter-branch will “rewrite history”, so it should not be undertaken lightly if you have any collaborators that have pulled any of your history that follows the addition of the “crud”).

Chris Johnsen