1

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.

4
  • it might be the handling of carriage return line feed. If it is the caes, setting git config core.autocrlf input will fix the issue Commented Nov 1, 2017 at 21:27
  • Can you explain what you mean by that? Carriage return... you mean I'm somehow adding extra lines to files? Commented Nov 1, 2017 at 21:35
  • Read up on the formatting and whitespace section in the following git-scm.com/book/gr/v2/Customizing-Git-Git-Configuration Commented Nov 1, 2017 at 21:49
  • This question seems more related to your local git repo and git, not related to TFS side. Commented Nov 2, 2017 at 7:22

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Doesn't this argument presume that I have modified the files by adding newlines at the end, and just can't see it? I literally haven't touched them. These are good tools though and I will definitely investigate further what the actual difference is
Yes it does. You can always check with the commands supplied if that's the case. Even though you haven't changed the files, some programs convert files on open. I can't tell you which process on your computer that changes them, but you have a process that does.
I haven't opened them or interacted with them in any way that I'm aware of. Hm...
I would first figure out which bytes that differ, and then look for culprits. If it is newlines, then I'd suspect IDEs and text editors. If it is some other byte, then I'd look elsewhere. Start by figuring out which bytes differ. It could be something else (like UTF-8 BOM), but it's almost always CRLF in my experience.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.