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 my working directory from (parts of) a commit. How can I do that ?
My use case is that I have several distinct features that are grouped together in a single commit and I'd like to test them one by one
Using cherry-pick -n
is not really satisfactory, since it leaves me with the dirty job of removing all the unrequired code. I'd really just like to pick the selected changes I want to test.
Simply right-click on a commit from the central graph and select Checkout this commit from the context menu. Yes, it's that easy.
In the list of branches, click the branch that has the commit that you want to cherry-pick. Click History. Drag the commit that you want to cherry-pick to the Current Branch menu and drop the commit on the branch that you want to copy the commit to.
In the Commit window, select the file you want to partially commit, then select the text you want to commit in the right pane, then right-click on the selection and choose 'Stage selected lines' from the context menu.
Using cherry-pick -n is not really satisfactory, since it leaves me with the dirty job of removing all the unrequired code. I'd really just like to pick the selected changes I want to test.
The job may have been a dirty one before, but with the advent of git checkout --patch
, you can now selectively discard changes, similar to git add -p
for adding.
You could use git reset --mixed HEAD^1
to revert the index, then pick the hunks you want with git add -i
.
The reset
will roll back the index to the previous commit (essentially un-committing whatever was the HEAD), but it won't touch the working tree. You can now stage the hunks you want, commit them and throw away the rest with a git reset --hard HEAD
.
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