Git tells me that file has changed when I simply save a file

320 Views Asked by At

Even though I did not change anything, Git tells me that file has changed whenever I save a file.

I cloned a repo, opened a random file, and hit save. here is what git diff shows me.

     1. `{{pathFor contextObject queryKey=queryValue hash=anchorTag}}`
     or
     2. ```
-        {{#with contextObject}}
+        {{#with contextObject}}
           {{pathFor queryKey=queryValue hash=anchorTag}}
         {{/with}}
        ```

But the line deleted and the line added are the same. This happens in multiple lines. Any ideas about why, and how to stop this?

Update

When I do git diff -R, I see a trailing whitespace:

-        {{#with contextObject}}
+        {{#with contextObject}}[trailing whitespace]

When I try to remove the whitespace manually, it is not there. Also, I have turned on Remove Trailing Whitespace option in Atom.

atom setting

Why is this happening?

2

There are 2 best solutions below

1
On

It could be that your editor automatically removes whitespace, or that it changes the type of newline or tabs to spaces. What happens when you diff using the diff command?

0
On

There is a package called the 'whitespace' package in Atom, disable it. The issue should go away.