Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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;
+}
[snip]

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

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Maybe this solution can work for you too: http://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.

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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