Skip to content

Instantly share code, notes, and snippets.

@triple-j
Created July 25, 2017 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triple-j/df3e0f11cfe3eca62ef5ececbbbb7b41 to your computer and use it in GitHub Desktop.
Save triple-j/df3e0f11cfe3eca62ef5ececbbbb7b41 to your computer and use it in GitHub Desktop.
Find all the files changed/deleted since a given commit
#!/bin/bash
OLDCOMMIT=$1
OUTDIR="__UPDATES__"
DELETED=""
FILES=`git diff --name-only $OLDCOMMIT`
rm --force --recursive "$OUTDIR"
IFS="
"
for FILE in $FILES; do
if [ -f "$FILE" ]; then
echo "Copying: $FILE"
mkdir --parents "$(dirname -- "$OUTDIR/$FILE")"
cp --force "$FILE" "$OUTDIR/$FILE"
else
echo "File no longer exists: $FILE"
DELETED="$DELETED $FILE\n"
fi
done
if [ -n "$DELETED" ]; then
echo ""
echo "Deleted Files:"
echo -e $DELETED
fi
@triple-j
Copy link
Author

triple-j commented Apr 3, 2019

Usage: __git-changes.sh <OLD_COMMIT>

Run this script in a folder containing a GIT repository, and it will copy any files that have been changed between the currently checked out commit and the commit given to the script. You can find the files in the newly created __UPDATES__ folder.

A list of files that have been deleted since the given commit will be displayed in the terminal.

Some things to be aware of...

This script will copy whatever is in the current working directory. So if you have uncommitted changes they will show up in the files copied to __UPDATES__.

The deleted files list is not entirely accurate. So don't rely too much on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment