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

后端 未结 5 1765
不知归路
不知归路 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 14:57

    Like other people have said, you can use e to edit the hunk you want to split up.

    To only add a portion of the hunk, you can delete the lines from the change you want to split out.

    +Line 1
    +Line 2
    +Line 3
    

    Lets say you want to keep Line 1 and Line 3 in one commit and Line 2 in another. All you have to do is delete Line 2:

    +Line 1
    +Line 3
    

    This will put Line 1 and Line 3 in your staging area. Line 2 will still be indexed but not staged.

提交回复
热议问题