(Git) Cherry-pick only parts of a commit
- Use
-n
flag to cherry-pick changes in a commit without committing them. Then reset the changes and re-stage only the desired parts before committing them. E.g.:git cherry-pick -n <COMMIT_HASH> git reset git add -p # Stage patches of current changes git commit
- Use
git checkout -p <COMMIT_HASH>
whichdiff
s the current commit against the specified commit, and allows to select patches of the diff to be staged.
References:
Written on November 16, 2021