22

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( true );
+    removeThis();
+    test( false );
 }
 else

How can I commit the change for test() only, and avoid committing removeThis() ? Each time I try to edit the hunk manually git tells me it does not apply cleanly.

vdboor
  • 21,914
  • 12
  • 83
  • 96

1 Answers1

27

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.

P Shved
  • 96,026
  • 17
  • 121
  • 165
  • 2
    Thanks! I also figured out my editor (`notepad2`) saved the file in LF line endings. Saving them in LRLF endings fixed the final problem. – vdboor Mar 03 '10 at 16:19
  • FYI, the comma's in front of the lines are typo's typing the post here, they are not in the source. Fixed them. – vdboor Mar 05 '10 at 14:22
  • @vdboor Just curious, why the LF-to-CRLF solves? Are you on Windows platform? – RayLuo Mar 02 '13 at 00:55
  • @Iceberg: I used to be for the job I was in, but not anymore. – vdboor Mar 03 '13 at 14:47
  • 2
    Pavel, the key to your answer was "The resultant text should look like a patch for the change you're committing." Easy to remember, and that's the part it's hard to remember, not "Press e to edit your hunk". :) – Mark Wilden Aug 09 '13 at 20:03