Last active
February 5, 2019 04:43
-
-
Save MCJack123/71ed25d6e2c8bc7f9aa4a1830ddd2f0b to your computer and use it in GitHub Desktop.
Quick-and-dirty git repository packer/unpacker
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
#!/bin/bash | |
if [ "$1" == "pack" ]; then | |
BNAME=`basename $2` | |
mkdir "._$BNAME" | |
git format-patch --root -o "._$BNAME" | |
git log > "._$BNAME/history.txt" | |
tar -cJf "$2" -C "._$BNAME" . | |
rm -r "._$BNAME" | |
elif [ "$1" == "unpack" ]; then | |
BNAME=`basename $2` | |
mkdir "._$BNAME" | |
tar -xJf "$2" -C "._$BNAME/" | |
rm "._$BNAME/history.txt" | |
for line in `cd ._$BNAME && find . -type f | sort -n`; do | |
if [ "$3" != "" ]; then | |
NUM=`echo $line | sed 's/^.\///g' | grep -o '^[0-9]*' | sed 's/^0*//g'` | |
if [ $NUM -gt $3 ]; then | |
break | |
fi | |
fi | |
git apply --binary --whitespace=nowarn "._$BNAME/$line" | |
done | |
rm -r "._$BNAME" | |
elif [ "$1" == "history" ]; then | |
tar -xOJf "$2" ./history.txt | |
else | |
echo "Usage: gitinafile <pack|unpack|history> <file> [last]"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment