Skip to content

Instantly share code, notes, and snippets.

@donatj
Created August 27, 2010 20:38
Show Gist options
  • Save donatj/554158 to your computer and use it in GitHub Desktop.
Save donatj/554158 to your computer and use it in GitHub Desktop.
Git Fast Patch Shell Script
#!/bin/sh
set -o errexit
# make sure we're at the root of git repo
if [ ! -d .git ]; then
echo "Error: must run this script from the root of a git repository"
exit 1
fi
if [ ! -d "$1/.git" ]; then
echo "Error: Paramater 1 must be host to a git repository"
exit 1
fi
if [ $# -eq 2 ]; then
commits=$2
else
commits=1
fi
#Patch Log
echo "Patched From: " > ~/fastPatch.log
pwd >> ~/fastPatch.log
git log -n $commits >> ~/fastPatch.log
#Patch
git format-patch -$commits --stdout > ~/fastPatch.patch
cd "$1"
#git stash
git apply --reject --whitespace=nowarn ~/fastPatch.patch
#git add .
#git commit -F ~/fastPatch.log
#git stash pop
echo "Patched With:"
cat ~/fastPatch.log
@donatj
Copy link
Author

donatj commented Aug 27, 2010

From a project with a git repo, use via

fast-patch.sh /z/my_other_project
to patch with the most recent commi

Or optionally
fast-patch.sh /z/my_other_project 2
to commit 2 (or more) of the previous commits

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