Git: Apply part of a commit to another branch
git cherry-pick -n <SHA>
will stage the changes but not commit them. You can then use git reset -p
to unstage the bits you don't want, or git reset HEAD
and git add -Ap
to stage only the changes you want.
If the parts you want to apply can be specified by path (i.e., you do not wish to specify hunks within one file) another solution is possible.
One approach is to form a patch from the commit, and apply it to your branch.
With the branch you wish to modify checked out:
git show <SHA> -- <relevant paths> | git apply
Will apply any changes in commit SHA, in paths relevant paths
to your current working copy.