-
Notifications
You must be signed in to change notification settings - Fork 298
Description
If you replace an existing file in a Git repository with the same file but without an LF character at the end of file, the last line will correctly show as modified. However, once you save the file in Vim an LF character is added at the end. Nevertheless, the hunk still indicates that the last line is modified until you reload the file.
To reproduce first create the Git repository with a test file.
mkdir test
cd test
git init
echo "test" > test
git add test
git commit -m "Test"
As you can see, there is an LF (0a) at the end of file.
❯ hexdump -C test
00000000 74 65 73 74 0a |test.|
00000005
Now remove the LF with vim.
vim -b test
:set noeol
:wq
The LF character is now removed and the line is correctly shown as modified.
❯ hexdump -C test
00000000 74 65 73 74 |test|
00000004
❯ git diff
diff --git a/test b/test
index 9daeafb..30d74d2 100644
--- a/test
+++ b/test
@@ -1 +1 @@
-test
+test
\ No newline at end of file
Open the file in Vim.
vim test

Save it in order to insert the LF character.
:w

As you can see, the 0a character has been inserted making the line 5B long instead of the 4B when the file was opened.
❯ hexdump -C test
00000000 74 65 73 74 0a |test.|
00000005
However, the hunk still indicates that the line is modified. Reloading the file fixes the issue.
:e test
