1

I am using Eclipse for local dev and GitHub as my remote git repo. Eclipse generates several artifacts that I don't want in my remote repo, but I forgot to add those to my .gitignore file. I pushed everything to the remote GitHub repo and realized that the following items were pushed (again, unintentionally):

myapp/
    <lots of other stuff>
    .classpath    --> undesired
    .settings     --> undesired
    .project      --> undesired
    bin/          --> undesired

So I went back and added the following to my .gitignore:

# Eclipse
.classpath
.project
.settings
bin/

I then committed & pushed. To my surprise, the files are still in my remote repo. I would have expected the following behavior:

  1. I push the .gitignore changes to GitHub
  2. GitHub sees that there are files in its myapp repo that violate the terms of the new .gitignore
  3. GitHub deletes these files/directories from the repo
  4. Now when I go to myapp on GitHub, I don't see them anymore

Is this not the case? What's the fix here?

DirtyMikeAndTheBoys
  • 1,077
  • 3
  • 15
  • 29

1 Answers1

0

Git does not parse .gitignore file on each commit on it and, of course, does not apply changes from .gitignore to the whole repository in its commit.

So you need to remove files manually (git rm).

If you need to have this files on your filesystem use git rm --cached

Community
  • 1
  • 1
aeryaguzov
  • 1,143
  • 1
  • 10
  • 21
  • 1
    Additionally, if you want to remove the files from your entire history, you can use the BFG Repo Cleaner: https://rtyley.github.io/bfg-repo-cleaner/ . Remember that modifies the SHA1s so you need to consider carefully if editing old history is right for your project and how you share/communicate that message to your other clones. – Jonah Graham Oct 19 '15 at 22:17