How to edit Git “add patch” hunks/diffs/lines during selective staging?

后端 未结 5 1737
不知归路
不知归路 2020-12-28 14:33

I have a source file where 2 features have been added. In order to allow cherry-picking, I\'d like to commit that in 2 phases: one for each feature. Until now, in similar si

5条回答
  •  北海茫月
    2020-12-28 15:04

    As Alan says, edit the patch by pressing e (instead of s) during git add -p. This will launch your editor with that hunk of the patch so that you can manually edit it. There are comments within the text that explain how to properly discard modifications and it's actually pretty easy.

    When you are done, note that you can test it with only the changes you've just added by doing git stash --keep-index. The changes you did not add to the index will be stashed away and you are now free to test just the changes that you are about to commit. When done, simply git stash pop or git stash apply to get the other changes back.

提交回复
热议问题