Skip to content

Instantly share code, notes, and snippets.

@Joaquin6
Created May 5, 2020 07:20
Show Gist options
  • Save Joaquin6/bd2c6d4a3235c06c34badfe842586faa to your computer and use it in GitHub Desktop.
Save Joaquin6/bd2c6d4a3235c06c34badfe842586faa to your computer and use it in GitHub Desktop.
If you want to clean all previous commit and thin up your repo. Warning: this operation will make you loose all previous commit
# find top 10 files
git rev-list --objects --all | grep -f <(git verify-pack -v .git/objects/pack/*.idx| sort -k 3 -n | cut -f 1 -d " " | tail -10)
echo -n "Clean all git commit?(y/n)? "
read answer
if [ "$answer" != "${answer#[Yy]}" ] ;then
git checkout --orphan latest_branch
git add -A
git commit -am "Delete all previous commit"
git branch -D master
git branch -m master
fi
## see https://github.com/18F/C2/issues/439
echo -n "Start?"
select yn in "Yes" "No"; do
case $yn in
Yes ) echo "Cleanup refs and logs"
rm -Rf .git/refs/original
rm -Rf .git/logs/
echo "Cleanup unnecessary files"
git gc --aggressive --prune=now
echo "Prune all unreachable objects"
git prune --expire now
break;;
No ) exit;;
esac
done
#git push -f origin master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment