Skip to content

Instantly share code, notes, and snippets.

@avioli
Created October 1, 2020 05:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avioli/0e2bc80ee189f0b3cfce1add600037c3 to your computer and use it in GitHub Desktop.
Save avioli/0e2bc80ee189f0b3cfce1add600037c3 to your computer and use it in GitHub Desktop.
Packages all current commits into a tar.gz archive and deletes all git tracked files (beware - deletes empty and untracked dirs, but leaves untracked files)
#!/usr/bin/env bash
git diff --name-status --exit-code >/dev/null
[[ "$?" == "1" ]] && { echo " --- found uncommited changes"; exit 1; }
echo "removing all git files and packaging .git dir into an archive"
set -e
git ls-files | while read f; do test -f "$f" && echo "$f"; done | xargs -n 30 -- rm -f
find . -type d -empty -delete
tar czf bare.tar.gz .git
rm -rf .git
echo "#!/bin/bash" > revive.sh
echo "set -e" >> revive.sh
echo "tar xf bare.tar.gz && git reset --hard" >> revive.sh
echo "rm bare.tar.gz revive.sh" >> revive.sh
chmod u+x revive.sh
echo "done. run ./revive.sh to reverse the process"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment