-
Use the comamnd
git filter-branch --force --index-filter \ 'git rm -r --cached --ignore-unmatch [FILE_TO_DELETE]' \ --prune-empty --tag-name-filter cat -- --all
-
After the filter branch is complete, verify that no unintended file was lost.
-
Now add a .gitignore rule
echo [FILE_DELETED] >> .gitignore git add .gitignore && git commit -m "ignore rule for [FILE_DELETED]"
-
Now do a push
echo [FILE_DELETED] >> .gitignore git push -f origin branch
Check this, this and this for further help. Just to be on the safer side, I would suggest you create a backup copy of the repo on your system before going ahead with these instructions.
References: StackOverflow original answer
Hey, i'm with the same problem but when typing the command at step 1, i get an error: fatal: bad revision ' --prune-empty'. Any clue?
– kevin
-
@kevin sorry, missed this comment. You can run it without that flag. Pruning would have removed any empty commit object.