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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With