Skip to content

Instantly share code, notes, and snippets.

@mootari
Last active August 29, 2015 14:17
Show Gist options
  • Save mootari/fd1a2a3389bf914dcd2b to your computer and use it in GitHub Desktop.
Save mootari/fd1a2a3389bf914dcd2b to your computer and use it in GitHub Desktop.
Attempts to find the commit a patch applies to cleanly. Usage: git-match-patch {branch} {patch-file}
#!/bin/bash
current=$(git rev-parse HEAD)
commits=$(git rev-list $1)
for rev in $commits; do
git checkout --quiet $rev
git apply --check $2 2>/dev/null
if [ $? == 0 ]; then
git log -n 1
exit 0
fi
done
echo "No commit found."
git checkout --quiet $current
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment