0

I set up a repo and checked in some files. Later on, I realized that I hadn't configured a .gitignore in my local solution so I went ahead and did that and then checked it in. Now I need to eliminate the files in the VSTS repo which the .gitignore should have prevented. I've done this in the past so I know it's not a big deal but I don't recall the steps. Can you please reply with the steps accomplish this?

DeanOC
  • 7,142
  • 6
  • 42
  • 56
user10067458
  • 215
  • 3
  • 7
  • 2
    Possible duplicate of [Applying .gitignore to committed files](https://stackoverflow.com/questions/7527982/applying-gitignore-to-committed-files) – DeanOC Jul 23 '18 at 22:17
  • Have you get the answer which helps you solve the problem? If yes, can you makr the answer? And it will also benefit others who meet similar question. – Marina Liu Jul 25 '18 at 10:01

2 Answers2

0

After adding file to .gitignore, Try using:

git rm --cached FILENAME

This will remove file from your repo but keep the file in your working directory, if this is what you want.

If you want to remove ignored file for good, you can use:

git rm FILENAME

In-order to add ignored file again in source control, you can use following command:

git add -f FILENAME
awefsome
  • 1,431
  • 1
  • 13
  • 11
0
git rm --cached `git ls-files -i --exclude-from=.gitignore`

from How to remove files that are listed in the .gitignore but still on the repository?

tymtam
  • 31,798
  • 8
  • 86
  • 126