From 04100733ce5b73cd5e1713e0b5a914928f569163 Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Fri, 1 Jul 2011 15:17:04 +0200 Subject: [PATCH] Add git-cherry-move Like cherry-pick, but to move instead of copy. --- git/git-cherry-move | 47 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 git/git-cherry-move diff --git a/git/git-cherry-move b/git/git-cherry-move new file mode 100755 index 0000000..fa854c8 --- /dev/null +++ b/git/git-cherry-move @@ -0,0 +1,47 @@ +#!/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() +{ + RET=$(git branch | sed --quiet "s/^\*\? \+${1}$/${1}/p") + if [ "$RET" != $1 ] ; 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^