When I do stage commits in my workspace I usually use the -p
option to go through each hunk of the changes. I find this useful to confirm my changes and as a check on typos and other silly errors.
I usually rebase
in my open source development work when a dev branch gets stale. However, sometimes I want to test out something on a throw away branch in my workspace and I don't want the entire branch because it is long and contains many commits that are not yet merged. I could git cherry-pick
but that appears to grab the entire commit. Sometimes these commits are large and I don't want the entire thing.
Is there any way to grab the commit via cherry-pick
but inspect the commit hunk by hunk as it is applied to a staging area before committing?
Presumably the user then stages only the components of the commit that they want.
Not sure it's the simplest way, but atomically it could look like
# first you cherry-pick without committing
git cherry-pick -n <commit-hash>
# then you unstage everything
git reset
# and stage hunk by hunk as usual
git add -p
# finally you discard everything else
git stash --keep-index