-
-
Save kateinoigakukun/33acba780c8f5e538fc21494b34fe9db to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
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