Created
October 2, 2017 17:37
-
-
Save travispaul/39f47be52da7c34491c30cd8293302c2 to your computer and use it in GitHub Desktop.
Alias for copying commits between forks
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
copycommit () { | |
if [ $# -lt 2 ]; then | |
echo -e "Usage:\n copycommit /path/to/repo commithash1 commithash2 ..." | |
return 1 | |
fi | |
repo="$1/.git" | |
shift 1 | |
if [ ! -d "$repo" ]; then | |
echo "$repo is not a git repo" | |
return 1 | |
fi | |
git --git-dir="$repo" format-patch -k -1 --stdout $@ | git am -3 --ignore-whitespace | |
if [ $? ]; then | |
echo '----' | |
echo 'Merge failed, running "git am --abort" and creating patch: ./tmp.patch' | |
git am --abort | |
git --git-dir=$repo format-patch -k -1 --stdout $@ > ./tmp.patch | |
echo 'Edit patch ("vi tmp.patch") and re-apply ("git am -3 -k < tmp.patch") or give up and copy pasta the code.' | |
return 1 | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment