Following is the script I'm using to rewrite the history of a submodule which is referenced in multiple parent repositories. This runs in Git bash in a windows environment.
#!/bin/bash
cd submodule_repo
git filter-branch --index-filter 'git rm -q --cached --ignore-unmatch files_to_remove' \--tag-name-filter cat -- --all
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d
git reflog expire --expire=now --all
git gc --prune=now
I need to somehow map the SHAs of the old commits to the newly created SHAs, so that I can update the same reference in the parent repositories. Is there a way to do it? I did look at Repository with submodules after rewriting history of submodule, but it's not really helping as I'm updating the original refs to make sure the files I'm removing are not repacked by any chance. I'm relatively new to using git so any guidance would be really appreciated.
Edit:
Following the steps mentioned in comments section of the accepted answer (by @torek) worked for me.