1

I have been working on a Net Core project in Visual Studio.

I just realized that all of the image files I have placed in my wwwroot folder have been uploaded to my GitHub repository.

I would like to remove these files from the repository but retain them locally in the VS project.
I have created a .gitignore file and placed it in the wwwroot directory to prevent this from happening again, but am not sure how to remove the files currently uploaded.

I have made several commits since the files were uploaded (but before I realized they were there) so I would prefer not to revert to that point.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250

1 Answers1

0

I would recommend to use the new git filter-repo which replaces BFG and git filter-branch.

Note: if you get the following error message when running the above-mentioned commands:

Error: need a version of `git` whose `diff-tree` command has the `--combined-all-paths` option`

it means you have to update git.


First: do that one copy of your local repo (a new clone)

See "Path based filtering":

git filter-repo --path file-to-remove --invert-paths

At the end, you can (if you are the only one working on that repository) do a git push --force

Then restore your files locally.
Since your .gitignore is already in place, they won't be added and committed in the future.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250