Skip to content

Instantly share code, notes, and snippets.

@cmcenearney
Last active December 17, 2015 06:59
Show Gist options
  • Save cmcenearney/5569211 to your computer and use it in GitHub Desktop.
Save cmcenearney/5569211 to your computer and use it in GitHub Desktop.
git fun: list files changed by most recent commit, copy to dev server (or wherever)
#!/bin/bash
# list files changed by the last commit
# and copy them to a target dir
TARGET=$1
MOST_RECENT=$(git log -n 1 --pretty=format:'%h')
PREV=$(git log --skip=1 -n 1 --pretty=format:'%h')
echo "Coping to $TARGET"
for i in $(git diff --name-only $MOST_RECENT $PREV)
do
# First create the target directory, if it doesn't exist.
mkdir -p "$TARGET/$(dirname $i)"
# Then copy over the file.
cp "$i" "$TARGET/$i"
done
echo "Done";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment