Skip to content

Instantly share code, notes, and snippets.

@shotasenga
Created September 2, 2016 05:03
Show Gist options
  • Save shotasenga/9d59c0a63320f9196744209c0973056c to your computer and use it in GitHub Desktop.
Save shotasenga/9d59c0a63320f9196744209c0973056c to your computer and use it in GitHub Desktop.
Git subcommand to export diff
#!/bin/bash
# Git subcommand to export diff
#
# `git export-diff <base> <target>`
# ...or
# `git export-diff <target>` base=HEAD
BASE=$1
TARGET=$2
WORK_DIR=/tmp/archive/$(date +%Y%m%d-%H%I%S)
if [ -z "$TARGET" ]; then
TARGET=$BASE;
BASE="HEAD";
fi
ROOT_DIR=$(git rev-parse --show-toplevel)
cd $ROOT_DIR
mkdir -p $WORK_DIR
git archive --prefix=root/ $BASE $(git diff --diff-filter=AMCR --name-only $TARGET $BASE) -o ${WORK_DIR}/archive.zip
unzip ${WORK_DIR}/archive.zip -d ${WORK_DIR}
open $WORK_DIR/root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment