I\'m looking for exactly the same behavior as
git add -i -p
But instead of composing a commit from my working directory, I\'d like to compose
dirty job of removing all the unrequired code
If this is not acceptable,
git cherry-pick -n ... # Starting from clean status
git reset # unstage
git add -p / -i […] # add hunks interactively
git restore . # wipe the rest (at root dir)
, for example if you want to merge into uncommited changes or don't want to spoil time stamps, then using git apply
like this may be a cleaner option:
git show | tee _.patch
edit _.patch # strip unwanted hunks
git apply -3 _.patch
(As long as git cherry-pick
and git apply
do not support -p
directly)
Note: Methods like git checkout / restore -p ...
do not consistently revert hunks from a specific commit but pick parts from a certain file state - possibly loosing changes in other later commits.