Add git-cherry-move

Like cherry-pick, but to move instead of copy.
This commit is contained in:
Matteo Cypriani 2011-07-01 15:17:04 +02:00
parent c335527e41
commit 04100733ce
1 changed files with 47 additions and 0 deletions

47
git/git-cherry-move Executable file
View File

@ -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 <src-branch> <dst-branch> [ 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^