1

I've committed time ago many folders that I should had ignored. I mean, the folders .vs (and its content) into every Visual Studio project.

That said, I've many folders/projects with .vs into it, to the same repo.

How can I untrack all of them and start ignoring now?

Is there a recursive git rm -r --cached? Or do I need to specify every path? And than I should add */.vs on gitignore right?

phd
  • 82,685
  • 13
  • 120
  • 165
markzzz
  • 47,390
  • 120
  • 299
  • 507
  • Do you need to remove them from your remote repository ? – Matthias Beaupère Aug 30 '18 at 08:22
  • @matthiasbe: it would be great. I mean: I could keep them in the "past" commits, but I'd like to remove it now, and for the future commits. – markzzz Aug 30 '18 at 08:23
  • Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Aug 30 '18 at 12:07

1 Answers1

2

In short, yes there is a git rm -r --cached command.

Once you have committed your updated .gitignore file along with other changes, un-track it by doing a git rm -r --cached . and then git add .

Now those files should be excluded from tracking.

Finally, git commit -m "Untrack unnecessary files"

Perceo
  • 93
  • 1
  • 7
  • So, first I add `.vs/` to `.gitignore`. Than I commit it. Than? Not sure how to untrack all `.vs/` folders already tracked. Can you show to me the real list of commands? – markzzz Aug 30 '18 at 07:31
  • 1
    To give more details : 1) add `*.vs` to .gitignore 2) `git rm -r --cached *.vs` in your root folder 3) commit your changes. – Matthias Beaupère Aug 30 '18 at 08:31
  • Note that this will delete the files from the other contributors to your repo. See more info [here](https://stackoverflow.com/a/936290/6400167) – Matthias Beaupère Aug 30 '18 at 08:32
  • @matthiasbe: in fact if I push these changes, and another user who is collaborating pull again from my remote repo, this will delete his own ".vs" folders on him local repo. Right? – markzzz Aug 30 '18 at 11:59
  • 1
    @markzzz exactly yes. You could ask them to store the *.vs folders before they pull you changes from origin, and then to put the folders back after the pull – Matthias Beaupère Aug 30 '18 at 12:07
  • @matthiasbe: I see. What if I want to do the same but keep files on every repo? Is it possibile? Some fancy commands? – markzzz Aug 30 '18 at 19:21
  • 1
    @markzzz I don't know any magic potion to do that, but [this](https://gist.github.com/scy/6636390) seems to really tackle this issue – Matthias Beaupère Aug 31 '18 at 07:27