Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JoshRosen
Forked from kfish/apply-patch.sh
Created June 24, 2016 23:10
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 JoshRosen/50ca46c4a2e6c519695288cb0dc3ae37 to your computer and use it in GitHub Desktop.
Save JoshRosen/50ca46c4a2e6c519695288cb0dc3ae37 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.
#!/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