Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove "no newline at end of file" changes from git stage

Tags:

git

newline

sed

I performed a sed search/replace on a large codebase, and for every file that sed passed over, it added a newline at the end if none was there previously. While it is good convention to end the last line with \n, this is a huge diff that is irrelevant to what I was trying to accomplish. The change affected hundreds of files, which I don't want to manually check and git checkout by hand.

Is there any way to selectively add or remove staged changes such that files that have only "no newline at end of file" will be ignored?

like image 956
heyitsbmo Avatar asked Aug 14 '14 21:08

heyitsbmo


1 Answers

From the linked related issue, I found that git diff --ignore-all-space would ignore files with only whitespace changes. git diff --ignore-all-space --name-only doesn't work as I expected it to, but this does:

git diff --ignore-all-space | grep "+++"

This gave me a list of files that have changes other than whitespace, which is small enough that I can just add them all manually to the stage and commit.

Thanks to everyone for the comments, they were very helpful.

like image 102
heyitsbmo Avatar answered Sep 18 '22 14:09

heyitsbmo