Skip to content

Commit 0809208

Browse files
committed
Merge branch 'hu/cherry-pick-previous-branch'
Just like "git checkout -" knows to check out and "git merge -" knows to merge the branch you were previously on, "git cherry-pick" now understands "git cherry-pick -" to pick from the previous branch. * hu/cherry-pick-previous-branch: cherry-pick: allow "-" as abbreviation of '@{-1}'
2 parents 6d3e1f2 + 182d7dc commit 0809208

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

builtin/revert.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ int cmd_cherry_pick(int argc, const char **argv, const char *prefix)
202202
memset(&opts, 0, sizeof(opts));
203203
opts.action = REPLAY_PICK;
204204
git_config(git_default_config, NULL);
205+
if (!strcmp(argv[1], "-"))
206+
argv[1] = "@{-1}";
205207
parse_args(argc, argv, &opts);
206208
res = sequencer_pick_revisions(&opts);
207209
if (res < 0)

t/t3501-revert-cherry-pick.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,24 @@ test_expect_success 'cherry-pick on unborn branch' '
109109
! test_cmp_rev initial HEAD
110110
'
111111

112+
test_expect_success 'cherry-pick "-" to pick from previous branch' '
113+
git checkout unborn &&
114+
test_commit to-pick actual content &&
115+
git checkout master &&
116+
git cherry-pick - &&
117+
echo content >expect &&
118+
test_cmp expect actual
119+
'
120+
121+
test_expect_success 'cherry-pick "-" is meaningless without checkout' '
122+
test_create_repo afresh &&
123+
(
124+
cd afresh &&
125+
test_commit one &&
126+
test_commit two &&
127+
test_commit three &&
128+
test_must_fail git cherry-pick -
129+
)
130+
'
131+
112132
test_done

0 commit comments

Comments
 (0)