Last active
November 12, 2020 12:02
-
-
Save l1x/01700e1b23072bec64df11124ae879aa to your computer and use it in GitHub Desktop.
Deleting a sensitive file from Git (including history) starting a certain commit hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
PATH_TO_BE_DELETED="${1}" | |
if [[ -z ${PATH_TO_BE_DELETED} ]]; then | |
echo "Path variable a is not set" | |
exit 1 | |
else | |
echo "Deleting $PATH_TO_BE_DELETED" | |
fi | |
STARTING_HASH=$(git log --pretty=format:"%h" -- ${PATH_TO_BE_DELETED} | tail -1) | |
echo "Starting $STARTING_HASH" | |
git filter-branch \ | |
--index-filter "git rm --cached -f -r --ignore-unmatch $PATH_TO_BE_DELETED" \ | |
--prune-empty -- $STARTING_HASH..HEAD |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When completed, you need to *force push the changes upstream
If someone has a local version affected by the rewrites they need to change their local branches to upstream: