Is there some way to stage individual lines of a file which has just been changed to include newline at EOF? I tried add -p, but it wouldn't split the relevant hunk into small enough parts, and it's well known that git-gui throws a "corrupt patch" error when dealing with files without a newline at the end. The relevant hunk:

 $courier:   "courier new", courier, freemono, "nimbus mono l", 
             "liberation mono", monospace;
-$monaco:    monaco, "lucida console", "dejavu sans mono", 
-            "bitstream vera sans mono", "liberation mono", 
-            monospace;
\ No newline at end of file
+$monaco:    monaco, "lucida console", "dejavu sans mono",
+            "bitstream vera sans mono", "liberation mono",
+            monospace;
+h1 {
+  font-size: 2em;

I'd like to commit everything up to h1 as a whitespace fix, and everything after in a separate commit.


Maybe this solution can work for you too: https://stackoverflow.com/questions/6276752/can-i-split-already-splitted-hunk-with-git

Edit the hunk and add \ No newline at end of file at the end of the + lines.

Edit: Now that I understood your requirement: Use git add -p to get into interactive mode, delete the +/- lines you don't want to be included in the add and save it then.

  • If I understand it correctly, it looks like the better solution would be to edit the hunk and simply remove the lines I don't want to stage. – l0b0 Feb 16 '12 at 12:19
  • Yes, but wouldn't that add the newline? – vasquez Feb 16 '12 at 12:33
  • I do want to stage the newline, an part of the whitespace fix. – l0b0 Feb 16 '12 at 14:53
  • "s/an/as/igmsx" – l0b0 Feb 17 '12 at 8:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.