Skip to content

Instantly share code, notes, and snippets.

@gottesmm
Created November 20, 2018 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gottesmm/7640843e1332e135bef4a71c553be03a to your computer and use it in GitHub Desktop.
Save gottesmm/7640843e1332e135bef4a71c553be03a to your computer and use it in GitHub Desktop.
#!/bin/bash
set -e
if [[ $# -lt 1 ]]; then
echo "Not enough arguments?!"
echo "$0 <hash1> ... <hashN>"
exit 1
fi
HASHES=( ${@:1} )
echo "Checking if hashes exist."
for h in "${HASHES[@]}"; do
echo -n " "
if git cat-file -e ${h}^{commit}; then
echo "Good hash: ${h}"
else
echo "Bad hash: $HASH?!"
exit 1
fi
done
# We name the branch after the last hash.
LAST_HASH=$(($# - 1))
BRANCH_NAME="pr-${HASHES[LAST_HASH]}"
OLD_BRANCH=$(git rev-parse --abbrev-ref HEAD)
git branch -f "$BRANCH_NAME" origin/master
git checkout "$BRANCH_NAME"
for h in "${HASHES[@]}"; do
if ! git cherry-pick "${h}"; then
exit 1
fi
done
git push self -f "$BRANCH_NAME:$BRANCH_NAME"
git checkout "$OLD_BRANCH"
git branch -D "$BRANCH_NAME"
set +e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment