Use git cherry-pick
with the -n|--no-commit
option and then interactively select what to commit:
git cherry-pick
...
-n
, --no-commit
Usually git cherry-pick
automatically creates a sequence of commits. This
flag applies the changes necessary to cherry-pick each named commit to your
working tree and the index, without making any commit. In addition, when
this option is used, your index does not have to match the HEAD commit. The
cherry-pick is done against the beginning state of your index.
This is useful when cherry-picking more than one commits' effect to your index
in a row.
So the sequence of commands will be the following:
git cherry-pick -n <commitid> # merge commitid into the index and working-tree
git reset # clear the index
git add -p # selectively add merged changes to the index
Alternatively, you can use git reset -p
to remove undesired hunks from the staging area:
git cherry-pick -n <commitid> # merge commitid into the index and working-tree
git reset -p # interactively remove from the index changes brought by commitid