Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious Carriage Return breaks diff tool #1930

Closed
1 task done
stravant opened this issue Nov 14, 2018 · 4 comments
Closed
1 task done

Spurious Carriage Return breaks diff tool #1930

stravant opened this issue Nov 14, 2018 · 4 comments

Comments

@stravant
Copy link

stravant commented Nov 14, 2018

  • I was not able to find an open or closed issue matching what I'm seeing

Setup

  • Which version of Git for Windows are you using? Is it 32-bit or 64-bit?
git version 2.17.1.windows.2
cpu: x86_64
built from commit: a60968cf435951d9411fc0f980a2e362d5cccea2
sizeof-long: 4
  • Which version of Windows are you running? Vista, 7, 8, 10? Is it 32-bit or 64-bit?
Microsoft Windows [Version 10.0.17134.407]
  • What options did you set as part of the installation? Or did you choose the
    defaults?
Editor Option: VisualStudioCode
Path Option: Cmd
SSH Option: OpenSSH
CURL Option: OpenSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Performance Tweaks FSCache: Enabled
Use Credential Manager: Enabled
Enable Symlinks: Disabled

Details

  • Which terminal/shell are you running Git from? e.g Bash/CMD/PowerShell/other

Tested and reproduced using both Git Bash and CMD.

git init
[Create list-of-words.txt, containing some lines of text, with CRLF line endings]
git add list-of-words.txt
git commit -m "Initial Commit"
[Edit list of words adding a naked Carriage Return character without a corresponding Line Feed in the middle of the list]
git diff
  • What did you expect to occur after running these commands?

The diff should show that a single line change where a carriage return (^M) was added in the middle of the file.

  • What actually happened instead?

The diff tool thinks that the entire file changed.

@tboegi
Copy link

tboegi commented Nov 18, 2018

Could you run
git config -l | grep core.autocrlf
and
git ls-files --eol
and post the output here, please ?

@stravant
Copy link
Author

git config -l | grep core.autocrlf -> core.autocrlf=true

ls-files before adding the suprious carriage return:
i/lf w/crlf attr/ list.txt

And after:
i/-text w/-text attr/ list.txt

@tboegi
Copy link

tboegi commented Nov 19, 2018

Thanks.
The thing is the "auto" treats file with a single CR as binary.
And that "binary" switches the CRLF conversion off, and suddenly ALL lines are changed.

The solution would be to use a .gitattributes file:
echo "list.txt text" >>.gitattributes

or better:
echo "* text=auto" >.gitattributes
echo "list.txt text" >>.gitattributes
git add .gitattributes
git commit -m "Add .gitattributes"

@stravant
Copy link
Author

Even though there are carriage returns in the files normally, a naked one looks like a random binary byte and makes the file binary...

That makes perfect sense actually. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants