Created
November 12, 2013 03:59
-
-
Save kfish/7425248 to your computer and use it in GitHub Desktop.
Apply a patch file that was produced with "git format-patch" using the patch command, and commit it using the message from the original commit.
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/bash | |
apply () { | |
filename=$1 | |
shift | |
patch_args=$* | |
gotSubject=no | |
msg="" | |
cat $filename | while read line; do | |
if [ "$line" == "---" ]; then | |
patch $patch_args -p1 < $filename | |
git commit -a -m "$msg" | |
break | |
fi | |
if [ "$gotSubject" == "no" ]; then | |
hdr=(${line//:/ }) | |
if [ "${hdr[0]}" == "Subject" ]; then | |
gotSubject=yes | |
msg="${hdr[@]:3}" | |
fi | |
else | |
msg="$msg $line" | |
fi | |
done | |
} | |
apply $* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Apply a patch file that was produced with "git format-patch" using the patch command, and commit it using the message from the original commit.
Unlike "git am", "patch" supports fuzzy matches. If "git am" fails, try running this command as:
to increase the fuzz factor to 3. Arguments after the patch filename are passed verbatim to patch.
Also, "patch" is not all-or-nothing; so if 1 of 7 hunks fail then this script will commit the 6 successful hunks, and you can inspect the rejected hunk in the foo.rej file then amend the commit.