Skip to content

Instantly share code, notes, and snippets.

@Haegin
Last active January 4, 2016 05:39
Show Gist options
  • Save Haegin/8576322 to your computer and use it in GitHub Desktop.
Save Haegin/8576322 to your computer and use it in GitHub Desktop.
Automates reverting back to a given SHA with Git and restoring the lost features after the revert.
#!/bin/bash
function revert_to {
SHA=$1
echo "Reverting to ${SHA}"
git diff -R --binary $SHA | git apply
echo "Reverted"
echo "Diff against ${SHA}"
git diff $SHA
}
if [ $# -ne 1 ]; then
exit "Usage: git me-back-to <SHA>"
else
revert_to $1
fi
#!/bin/bash
function restore_feature {
BRANCH_NAME=$1
SHA=$2
echo "Restoring feature merged in ${SHA}"
git checkout master
git co -b ${BRANCH_NAME}-remerge
git diff -R --binary ${SHA} "${SHA}^" | git apply
echo "Restored feature on #{BRANCH_NAME}-remerge."
echo "Check the diff against master below and re-run the tests."
git diff master
}
if [ $# -ne 2 ]; then
exit "Usage: git the-feature-back <BRANCH_NAME> <ORIGINAL_MERGE_SHA>"
else
restore_feature $1 $2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment