Last active
July 22, 2020 03:07
-
-
Save arawako/7f6b849d016efdafcf8bea15e360d1f4 to your computer and use it in GitHub Desktop.
A script that using git filter-branch for cleaning and not tracking sensible data in a repository of etckeeper or any git repository
This file contains 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
#!/bin/bash | |
origin=/etc | |
tmp=$(mktemp -d) | |
cp -a $origin/. $tmp | |
cd $tmp | |
linestoremove=$(sed -n '/# BEGIN section managed by ansible/,/# END section managed by ansible/p' .gitignore | sed -e '/# BEGIN section managed by ansible/d' -e '/# END section managed by ansible/d' -e 's_^/__' | xargs) | |
filter=$(git filter-branch -f --index-filter 2>&1 1>/dev/null "git rm -r --cached --ignore-unmatch $linestoremove" --prune-empty -- --all) | |
if [[ $filter != "" ]] | |
then | |
exit -1 | |
else | |
git reflog expire --expire=now --all | |
git gc --prune=now --aggressive | |
cp -a $origin/.git ~/.git.$(date +%Y%m%d%H%M%S) | |
rm -rf $origin/.git | |
cp -a .git $origin | |
rm -rf $tmp | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment