Created
September 2, 2016 05:03
-
-
Save shotasenga/0d73d9f5cce167aa971152bd12118493 to your computer and use it in GitHub Desktop.
Git subcommand to export diff
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 | |
# 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