Home > Software design >  git apparently keeps saying that a file has been modified when it has not
git apparently keeps saying that a file has been modified when it has not

Time:07-07

I am experiencing a curious situation, probably related to this question, but I'd like to better understand what is going on here.

I have a repository where right after a clone git status reports that a file has been modified.

I created a minimal reproduction here, with a repo containing just the ignore list, a very trivial .gitattributes, and the file causing me headaches: gradlew.bat.

All my attempts in the following are performed using Linux/ZSH (the issue has been reproduced on multiple Linux installations and shells).

Right after clone, if I run git status, I get:

❯ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   gradlew.bat

no changes added to commit (use "git add" and/or "git commit -a")

And if I try to check out the unmodified version with git checkout HEAD -- gradlew.bat, then issue git status again:

❯ git checkout HEAD -- gradlew.bat
❯ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   gradlew.bat

no changes added to commit (use "git add" and/or "git commit -a")

Okay then, I downloaded the file directly from GitHub, and checked the hashes:

❯ md5sum gradlew.bat
6b56324406b764fd6c5d4d7d215a3cd7  gradlew.bat
❯ sha512sum gradlew.bat
d4fef021e30640670fe20243e4fc4f0336b2f118f8c172c138a8c0c3028c93b12da9479812cede4196401bbc87ce9df89573dbec7378373cafafca6698867f55  gradlew.bat

Which are exactly the same of the file git mark as changed:

❯ md5sum gradlew.bat && sha512sum gradlew.bat
6b56324406b764fd6c5d4d7d215a3cd7  gradlew.bat
d4fef021e30640670fe20243e4fc4f0336b2f118f8c172c138a8c0c3028c93b12da9479812cede4196401bbc87ce9df89573dbec7378373cafafca6698867f55  gradlew.bat

This means it's not even matter of LF/CRLF line endings.

git diff is not helpful either, as it just suggests that the file changed entirely:

diff --git a/gradlew.bat b/gradlew.bat
index ac1b06f..107acd3 100755
--- a/gradlew.bat
    b/gradlew.bat
@@ -1,89  1,89 @@
-@rem
-@rem Copyright 2015 the original author or authors.
-@rem
-@rem Licensed under the Apache License, Version 2.0 (the "License");
-@rem you may not use this file except in compliance with the License.
-@rem You may obtain a copy of the License at
-@rem
-@rem      https://www.apache.org/licenses/LICENSE-2.0
-@rem
-@rem Unless required by applicable law or agreed to in writing, software
-@rem distributed under the License is distributed on an "AS IS" BASIS,
-@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-@rem See the License for the specific language governing permissions and
-@rem limitations under the License.
-@rem
-
-@if "           
  • Related