Skip to content

Instantly share code, notes, and snippets.

@biplobice
Forked from josh-taylor/git-archive-patch.sh
Created March 31, 2022 02:58
Show Gist options
  • Save biplobice/12151ee4de8871e75dd1df36dd185115 to your computer and use it in GitHub Desktop.
Save biplobice/12151ee4de8871e75dd1df36dd185115 to your computer and use it in GitHub Desktop.
Creates an archive of all files changed in a git repository since a given commit.
#!/bin/bash
# Explains how to use the script
usage()
{
cat << EOF
usage: $0 options
$0 -o output_file.zip commit_from [commit_to]
Description:
The script creates a zipped archive of only modified files in a git repository
OPTIONS:
-h Shows this message
-o Optional. Sets the output file.
EOF
}
# Create the variables used
FILENAME=
# Extract the arguments
while getopts "ho:" flag
do
case $flag in
h)
usage
exit 1
;;
o)
FILENAME=$OPTARG
shift
;;
esac
shift
done
FROM=$1
TO=$2
: ${TO:="HEAD"}
git diff -z --name-only $FROM $TO | xargs -0 git archive $TO -o $FILENAME --
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment