Hunk editing in git checkout –patch


When you run git checkout --patch, you get to discard changes in the working directory interactively. The e command, which lets you edit the hunk before discarding it, is the trickiest one for me. This week I’ve finally gone and learned how to work the darned thing.

You start with a diff that would transform the state of the index into the state of the working directory. The third state, in your heart, is what you want to have in the working directory. Edit the diff so that it would transform the desired state into the state of the working directory. Then, git applies the reverse of the patch to the working directory, bringing it to the desired state.

It’s different from what you do for git add --patch, so don’t get confused 😉.

My last post was about either Cloud services, summer 2016 or Setting all your clocks at once. Find out which.