From: Marc Weber <marco-oweber@gmx.de>
To: git <git@vger.kernel.org>
Subject: Re: cherry picking several patches at once
Date: Sun, 24 Jan 2010 16:31:43 +0100 [thread overview]
Message-ID: <1264345006-sup-8582@nixos> (raw)
In-Reply-To: <94a0d4531001240510g25ea3398qdd0c7b98f9b81209@mail.gmail.com>
> Ok, in that case we would just need a cherry-pick that can commit to a
> separate branch, however I don't think git internals allow that kind
> of thing.
Which is the best way to implement this git-cherry-push command?
# naive implementation (BASH function):
gitCherryPush(){
# start a subshell so that failures don't quit your shell because of
# set -e
(
set -e
local branch=$(cat .git/HEAD | sed 's@ref: refs/heads/\(.*\)@\1@')
local otherBranch=$1; shift
commits="$(
for range in "$@"; do
local HAS_DOTS=${range%%*..*}
# add -1 if commit is not a range
git rev-list --reverse ${HAS_DOTS:+-1} "$range"
done
)"
echo "checking out other branch"
git checkout "$otherBranch"
echo "$commits" | while read c; do
git cherry-pick "$c" || {
echo "cherry-picking $c failed. fix it, exit 1 to abort. Starting subshell now"
$SHELL || [ "$?" != 1] || return
}
done
echo "checking out original branch $branch"
git checkout $branch
)
}
zsh completion:
compdef _gitCherryPush gitCherryPush
_gitCherryPush(){
typeset -A opt_args
_arguments -S \
':branch to which to move commit range:__git_branch_names' \
':branch to which to move commit range:__git_commit_ranges2'
}
Example usage (push last 5 commits)
gitCherryPush branch-to-push-to HEAD~4 HEAD~4..HEAD
Can I checkout the other branch without touching the working copy? I
don't think so because cherry-pick will fail operating if working
directory is not clean, correct?
Is something like this worth comitting to the main repo?
Marc Weber
prev parent reply other threads:[~2010-01-24 15:31 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-01-21 16:11 cherry picking several patches at once Felipe Balbi
2010-01-22 23:57 ` Felipe Contreras
2010-01-23 0:24 ` Marc Weber
2010-01-23 11:17 ` Sverre Rabbelier
2010-01-24 10:52 ` Felipe Balbi
2010-01-24 13:10 ` Felipe Contreras
2010-01-24 15:31 ` Marc Weber [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1264345006-sup-8582@nixos \
--to=marco-oweber@gmx.de \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).