4

I’m working with Rails and added the directory tmp and the Gemfile to my .gitignore. But every time I change it, git status tells me, that it changed. On both machines. On my developer machine and on the server. Kind of annoying.

Contents of .gitignore:

.DS_Store
data/export/*.csv
tmp/*
*.rbc
*.sassc
.sass-cache
capybara-*.html
.rspec
/.bundle 
/vendor/bundle 
/log/* 
/tmp/* 
/db/*.sqlite3 
/public/system/* 
/coverage/ 
/spec/tmp/* 
**.orig 
config/*.yml 
rerun.txt 
pickle-email-*.html 
Gemfile*
Mike Williamson
  • 4,915
  • 14
  • 67
  • 104
Ulf
  • 451
  • 1
  • 5
  • 13
  • 1
    what is the content of your .gitignore? – manojlds Apr 27 '11 at 20:35
  • .DS_Store data/export/*.csv tmp/* *.rbc *.sassc .sass-cache capybara-*.html .rspec /.bundle /vendor/bundle /log/* /tmp/* /db/*.sqlite3 /public/system/* /coverage/ /spec/tmp/* **.orig config/*.yml rerun.txt pickle-email-*.html Gemfile* – Ulf Apr 27 '11 at 20:36
  • Add to your question and try to format it :) – manojlds Apr 27 '11 at 20:37
  • Possible duplicate of [.gitignore is not working](http://stackoverflow.com/questions/11451535/gitignore-is-not-working) – Emil Laine Feb 12 '17 at 14:13

2 Answers2

15

It could be that git is already tracking the files. Try git rming them:

git rm --cached Gemfile

(although you probably should have the Gemfile under version control)

and for the tmp dir:

git rm -r --cached tmp

the --cached is so that the working file will not be deleted, and -r is to recursively remove from a directory.

After this git should respect .gitignore.

matt
  • 78,533
  • 8
  • 163
  • 197
  • Removing the Gemfile this way worked. The tmp dir didn’t. I keep getting this error when trying to: fatal: pathspec 'tmp' did not match any files – Ulf Apr 27 '11 at 21:20
  • @ulf sounds like you don't have any files in `tmp` being tracked. Try adding/changing a file in there and see if git notices. – matt Apr 27 '11 at 21:53
1

If your tmp and GemFile directories are already versioned, Git will not ignore them.

Either unversion them, by doing something like:

git rm -r --cached tmp
git commit -am "removing tmp"

( --cached so that they will remain in your working directory)

, or ignore that they are not ignored ( :) ) or do something like:

git update-index --assume-unchanged tmp/**

The above command "temporarily ignores" the changes to the folders that are already versioned.

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • As far as I know (its maybe wrong, too lazy to test it) git will ignore the changes, even if they are already versioned. So yeah, you are right, they remain versioned, but no, they should not appear on `git status`. – KingCrunch Apr 27 '11 at 20:43