Removing a file in Git repo but file doesn't exist

506 Views Asked by At

In committing and pushing to my repo, I get the following error: enter image description here

The issue is that I've already manually deleted the video file. The video does not exist anywhere in my repo. I also tried to git rm src/assets/video/Greensleeves and it says fatal: pathspec src/assets/video/Greensleeves did not match any files.

How can I get passed this so that I can commit/push?

enter image description here

1

There are 1 best solutions below

4
On BEST ANSWER

Try and apply the new git filter-repo, which does replace the old git filter-branch or BFG.

It has many usage examples, including path-based filtering, in order for you to remote the src/assets/video/Greensleeves file in past commits:

To keep all files except these paths, just add --invert-paths:

git filter-repo --path src/assets/video/Greensleeves --invert-paths

Then git push --force (that does rewrite the history of your repository, so make sure to notify any other collaborator)

Since it must be done on a fresh clone:

  1. Don't touch anything to your current clone folder
  2. Create a separate clone of the repository, where you do the filter repo
  3. In that second clone, now cleaned (no more big file in its history), import your work from your first repo

That is, for point 3:

cd /path/to/second/clone
git --work-tree=/path/to/first/original/clone add .
git commit -m "Import work from first clone"
git push --force