data princess
data princess

Reputation: 1158

Git suddenly lists every file in the repo as modified

This has happened to me a couple times now, so I wondered what I could possibly be doing to cause it.

My team has a TFS git repo. I am working on a branch, say my-branch. I'm modifying some R scripts, and commit frequently. A git status shows something like

Your branch is up-to-date with 'origin/my-branch'.
Changes not staged for commit:
    modified:   path/to/script.R

However, sometimes, even when I'm just working on this one script, a git status suddenly shows this, where every file in the repo is shown as modified even though I've only been working on one thing:

Your branch is up-to-date with 'origin/my-branch'.
Changes not staged for commit:

    modified:   other/path/to/scripts.cpp
    modified:   path/to/script.R
    modified:   path/to/somethingElse.txt
    modified:   path/toward/otherStuff.csv
    modified:   path/toward/Wiki
    modified:   really/every/file

If I run a git diff on these, there doesn't appear to be any difference. And I know I can just revert to the previous commit, but then I lose the work I just did. Is there anything I could be doing to cause this? It's really freaky.

Upvotes: 1

Views: 408

Answers (2)

gzh
gzh

Reputation: 3596

By default, git diff will show line ending changes, except you use --ignore-space-at-eol, --ignore-space-change or --ignore-all-space to suppress it.

Another reason you can not show what is changed with git diff is the file permission is changed, you can use "git status -v" to get more information.

Upvotes: 0

gogstad
gogstad

Reputation: 3739

If git shows the files as modified, it means that they differ. It may not be possible to render the difference using printable characters (that's why the output of git diff doesn't show anything). If you do a byte-by-byte comparison, you will find a difference.

As others have suggested, the most likely suspect is Microsoft's very own way of encoding the Enter-key. Windows will write two bytes for every time you press Enter, 0x0d and 0x0a, also known as CR and LF. A google search for "git crlf problems" should take you a long way.

If you want to verify for yourself exactly what the difference is, here's how you do it:

  1. Make a copy of a modified file and revert the original, so that you have two files—one modified and one not.
  2. If you are not on windows, simply compare them: diff <(hexdump -C file1.txt) <(hexdump -C file2.txt) alternatively diff <(xxd file1.txt) <(xxd file2.txt). I would keep an eye out for 0a and 0d
  3. If you are on windows, you'll need some third party tool. HxD is not too bad, although the web page is terrible.

If you're on windows and only working with windows, you can do

git config --global core.autocrlf false

I would advice to read up on the alternatives though. See https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#__code_core_autocrlf_code

Upvotes: 1

Related Questions