1

Somehow I accidentally committed a .sln.docstates file. Now I added it to the gitignore, however it won't be ignored. I think this is because I already committed it once. Don't know when!

Is there a possibility to make this gitignore rule working? How can I delete it from my repository?

*.sln.docstates

Marco
  • 4,817
  • 5
  • 34
  • 75

2 Answers2

3

Remove it this way:

$ git rm --cached \*.sln.docstates

…then the .gitignore should be honoured.

Jay
  • 56,361
  • 10
  • 99
  • 123
1

It depends on whether you have pushed the repository changes or the changes are local.

If you already pushed the changes to the remote repository then you are not supposed to rewrite history.

If your changes are only local you use git log .sln.docstates to find out the history of the files and locate the commit where you added the file. The removal of the file from commits requires some git filter-branch magic, see a corresponding answer.

The situation is simpler if the file is only present in the most recent unpublished commit: you can use git rm --cached .sln.docstates and git commit --amend. (The --cached switch tells git to don't touch your files and remove it from the index only, and then you modify your last commit instead of creating a new using the --amend switch.)

Community
  • 1
  • 1
bandi
  • 4,204
  • 3
  • 25
  • 24