Last active
August 29, 2015 14:17
-
-
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}
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 | |
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