Untangle two lines with `git add -p`

后端 未结 1 1201
孤街浪徒
孤街浪徒 2021-02-05 06:19

I\'ve got a file with the following changes:

# Manual hunk edit mode -- see bottom for a quick guide
@@ -280,6 +281,7 @@
 if( foo )
 {
     bla();
-    test( tru         


        
1条回答
  •  太阳男子
    2021-02-05 06:47

    How can I commit the change for test() only, and avoid committing removeThis() ?

    That's simple.

    1. Enter add -i mode, then select 5: [p]atch by pressing pEnter.

    2. Choose your file by entering its number and press Enter to start editing patches.

    3. Press e to edit your hunk (you seem to have succesfully reached here by doing git add -p instead).

    4. Delete the line with removeThis() completely, with + sign at the beginning as well. Do not touch anything else! The resultant text should look like a patch for the change you're committing.

    5. Save the file and exit the editor.

    The patch will apply well. I've just checked. Check again too--maybe it's another hunk that doesn't apply?

    Other than that, your , symbols near the +/- look suspicious. Perhaps, your patch and diff programs are somehow out of sync? Try removing the ,s from the hunk as well.

    0 讨论(0)
提交回复
热议问题