Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
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

Your Answer


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.