As "git cherry-pick -" or "git merge -" is convenient to switch back to or merge the previous branch, "git cherry-pick -" is abbreviation of "git cherry-pick @{-1}" to pick up a commit from the previous branch conveniently. Signed-off-by: Hiroshige Umino <hiroshige88@xxxxxxxxx> --- builtin/revert.c | 2 ++ t/t3512-cherry-pick-last.sh | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100755 t/t3512-cherry-pick-last.sh diff --git a/builtin/revert.c b/builtin/revert.c index 1d2648b..cb403f8 100644 --- a/builtin/revert.c +++ b/builtin/revert.c @@ -234,6 +234,8 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix) memset(&opts, 0, sizeof(opts)); opts.action = REPLAY_PICK; git_config(git_default_config, NULL); + if (!strcmp(argv[1], "-")) + argv[1] = "@{-1}"; parse_args(argc, argv, &opts); res = sequencer_pick_revisions(&opts); if (res < 0) diff --git a/t/t3512-cherry-pick-last.sh b/t/t3512-cherry-pick-last.sh new file mode 100755 index 0000000..8b05f81 --- /dev/null +++ b/t/t3512-cherry-pick-last.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +test_description='Test cherry-pick -' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo hello >world && + git add world && + git commit -m initial && + git branch other && + echo "hello again" >>world && + git add world && + git commit -m second +' + +test_expect_success '"cherry-pick -" does not work initially' ' + test_must_fail git cherry-pick - +' + +test_expect_success 'cherry-pick the commit in the previous branch' ' + prev=$(git rev-parse HEAD) && + git checkout other && + git cherry-pick - && + test "z$(git rev-parse HEAD)" = "z$prev" +' + +test_done -- 1.8.3.3 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html