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.
These changes mean that metadata about your file changed, however the content of your file did not. If you're working in a group, this may start to intefere with pushes or just add noise to your commits.
It indicates that you do not have a newline (usually \n , aka LF or CRLF) at the end of file. That is, simply speaking, the last byte (or bytes if you're on Windows) in the file is not a newline.
The main difference between the commands is that git diff is specially aimed at comparisons, and it's very powerful at that: It can compare commits, branches, a single file across revisions or branches, etc. On the other hand, git status is specifically for the status of the working tree.
To avoid this, always do git add -p
, and pick only relevant diffs to avoid unwanted changes to be committed.
And change your editor settings to match the conventions used in the project.
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