Last active
August 29, 2015 14:10
-
-
Save kekssw/2fb6cdc24c538ac33d1b to your computer and use it in GitHub Desktop.
git-transplant
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 | |
if [ "$#" -lt 2 ] | |
then | |
cat << EOM | |
Usage: git-transplant <FROM> <TO> <UPSTREAM> | |
Transplants <FROM> .. <TO> commit range (inclusive) on top of <UPSTREAM>. | |
If <FROM> is a number, transplant that number of commits ending at <TO> instead | |
(i.e. <TO>~<FROM> .. <TO> range). | |
<UPSTREAM> defaults to current branch (HEAD). | |
EOM | |
exit 1 | |
fi | |
DEPTH=$1 | |
TO=$2 | |
if [ "$DEPTH" -eq "$DEPTH" ] 2>/dev/null | |
then | |
FROM=$TO~$DEPTH; | |
else | |
FROM=$DEPTH~1 | |
fi | |
UPSTREAM=${3-HEAD} | |
BRANCH=$(git rev-parse --abbrev-ref $UPSTREAM) | |
ONTO=$(git rev-list $UPSTREAM --abbrev-commit -1) | |
echo -e "\nTransplanting $FROM..$TO onto $BRANCH (was at $ONTO)\n" | |
set -x | |
git checkout $TO | |
git branch -f $BRANCH | |
git rebase -i --onto $ONTO $FROM $BRANCH; | |
set +x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍