#!/bin/sh # # git-cherry-move, Copyright © 2011 Matteo Cypriani # # This program is free software. It comes without any warranty, to # the extent permitted by applicable law. You can redistribute it # and/or modify it under the terms of the Do What The Fuck You Want # To Public License, Version 2, as published by Sam Hocevar. See # http://sam.zoy.org/wtfpl/COPYING for more details. # # This script moves a commit from a branch head to another. It is # the equivalent of git cherry-pick followed by git reset. set -e assert_branch_exists() { if ! git for-each-ref refs/heads | grep "/${1}$" >/dev/null ; then echo "The branch $1 does not exist!" exit 2 fi } if [ $# -lt 2 ] ; then echo "Usage:" echo " $0 [ reset-arg ]" echo -n "'reset-arg' is passed to the final reset" echo " (can be --hard for example)." exit 1 fi assert_branch_exists "$1" SRC="$1" shift assert_branch_exists "$1" DST="$1" shift git checkout "$DST" git cherry-pick "$SRC" git checkout "$SRC" git reset $1 HEAD^