Created
August 27, 2010 20:38
-
-
Save donatj/554158 to your computer and use it in GitHub Desktop.
Git Fast Patch Shell Script
This file contains 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/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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