Skip to content

Instantly share code, notes, and snippets.

@travispaul
Created October 2, 2017 17:37
Show Gist options
  • Save travispaul/39f47be52da7c34491c30cd8293302c2 to your computer and use it in GitHub Desktop.
Save travispaul/39f47be52da7c34491c30cd8293302c2 to your computer and use it in GitHub Desktop.
Alias for copying commits between forks
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