After cloning a git repository from Github, if I open a file, make no changes, and save the file, the following shows up in the output of git diff:
-@import "sync.scss";
\ No newline at end of file
+@import "sync.scss";
As I understand it, \ No newline at end of file is supposed to mark the end of the file when no newline is present. Does this diff mean git thinks the last line has been moved to after the end of the file? Is there any way to avoid this? I’d like to contribute to this project without adding junk whitespace changes to my commits.
This seems like an issue with line endings. I’m fairly confident the file was originally saved on a Mac using Unix line endings. That’s the same setup that I’m using, so I’m not sure what is causing the document to change when I save it.
The
\ No newline at end of filebelongs to the line above it (meaning the line didn’t end with a\n). Your current line seems to have a newline at the end which is why you don’t see the ‘No newline’ message after it; and why there is a change at all.(warning: personal oppinion below)
I’d advise you to always end a file with a newline, especially when working in a unix/linux environment. It may be that this is seen as ‘junk’ by some (ask the project maintainer for his opinion on this to be sure), but when using posix tools – starting with a simple
cat– a missing newline will be a nuisance at best and break scripts transforming the code at worst.