Cherry-pick is, behind the scenes, a merge operation. Git performs merges in the index—so no, there is no way to do this other than using the index / staging-area. (But see below.)
If you don't want to commit the result in the current branch, just use some other branch (git checkout -b <newbranch>
) or a detached HEAD (no branch at all: git checkout --detach HEAD
). You can also use a mixed reset, as lucas-reineke suggested in a comment, to make the commit in the current branch and then move the current branch back one commit. This has the side effect of resetting the index to match the adjusted (post-cherry-pick) HEAD, leaving you with the state you originally asked for.
You can use git cherry-pick -n HEAD
followed by git reset --mixed HEAD
(with no path names listed) to get the same result: the cherry-pick takes place in the index, updating the work-tree as a side effect, without committing, and then the reset copies the files from the HEAD
commit back into the index, leaving the work-tree undisturbed. Note that --mixed
is the default, so git reset
without --soft
or --hard
does --mixed
even if you don't include an explicit --mixed
(it's useful to make sure you did not make any typos in the command, though).
These are the two ways you would normally do this. There is one more possibility, though: while Git has the index—the one distinguished index that goes with the primary work-tree for the repository—you can redirect Git to your own alternative index, using the GIT_INDEX_FILE
variable. You could set this to the name of a temporary file that does not yet exist, run git reset
to create that temporary index file and fill it in, then run git cherry-pick -n <commit>
to update the temporary index. You can then unset GIT_INDEX_FILE
and remove the temporary file. The result is a cherry-pick that uses your temporary index, instead of the normal index, that alters the work-tree files as a side effect. Note that this is the same amount of work as doing the cherry-pick in the normal index and then resetting the normal index. It may be useful for some sort of scripted work-flow, however. Beware of cherry-picks that fail and therefore leave merge conflicts in the index!
git reset HEAD~
? – Amaurosis