Is there a preferred method of reverting part of a previous commit, along the lines of partially reverting unstaged changes (git checkout -p
) and partially adding unstaged changes (git add -p
)?
i.e. I have a commit several (or even, many) commits back that contains both wanted and unwanted changes and I want to selectively revert some of those changes while keeping others.
My current workflow is not fun:
git diff commit commit^ > selective.diff
cp selective.diff selective2.diff
nvim selective2.diff
# change unwanted - to ' ' and remove unwanted +, then save
rediff selective.diff selective2.diff | rewrite selective2.diff
git apply selective2.diff
and pray the patch takes
git revert --no-commit
git reset --patch # or `git checkout --patch` if you're sure
I can only think of something like
git revert commit --no-commit
git reset # now the changes are unstaged
git add -p
...
git commit
But I do not know if it is more practicable than your solution, though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With