git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Bug in EOL conversion?

From
SNStefan Norgren <stefan.norgren@gmail.com>
Date
Jan 23, 2013, 02:44 UTC
Message-ID
<CANrZfmGXtKcB+i_xhNJELftRc1pC2TJKKhOieHm=5Qkni9OKrA@mail.gmail.com>
Hi,

The EOL conversion does not behave as indicated by output message from add and commit. Here is my test case executed on Windows 7 64 bit.

$ git --version git version 1.8.0.msysgit.0 $ which git /cygdrive/c/Program Files (x86)/Git/cmd/git $ git config --list core.symlinks=false core.autocrlf=true color.diff=auto color.status=auto color.branch=auto color.interactive=true pack.packsizelimit=2g help.format=html http.sslcainfo=/bin/curl-ca-bundle.crt sendemail.smtpserver=/bin/msmtp.exe diff.astextplain.textconv=astextplain rebase.autosquash=true user.name=Stefan user.email=stefan@---.com core.repositoryformatversion=0 core.filemode=false core.bare=false core.logallrefupdates=true core.symlinks=false core.ignorecase=true core.hidedotfiles=dotGitOnly

-- Note core.autocrlf=true. -- Created withcrlf.txt with one character and one CRLF line feed. File size 3 bytes. -- Created withlf.txt with one character and one LF line feed. File size 2 bytes. -- Now let's init repository.

$ git init Initialized empty Git repository in D:/Dev/workspaces/gittest/.git/ $ ls -la total 10 d---------+ 1 Stefan None 0 Jan 23 02:12 . d---------+ 1 Stefan None 0 Jan 23 02:10 .. d---------+ 1 Stefan None 0 Jan 23 02:13 .git ----------+ 1 Stefan None 3 Jan 23 01:55 withcrlf.txt ----------+ 1 Stefan None 2 Jan 23 01:55 withlf.txt

-- Note no .gitattributes file that will affect EOL conversion.

$ ls -la .git/info/ total 5 d---------+ 1 Stefan None 0 Jan 23 02:12 . d---------+ 1 Stefan None 0 Jan 23 02:13 .. ----------+ 1 Stefan None 240 Jan 23 02:12 exclude

-- Note no attribute file in .git/info/ that will affect EOL conversion.
$ git add *
warning: LF will be replaced by CRLF in withlf.txt.
The file will have its original line endings in your working directory.
$ git commit -m 'Testing EOL'
[master (root-commit) 9a0b2f5] Testing EOL
 2 files changed, 2 insertions(+)
 create mode 100644 withcrlf.txt
 create mode 100644 withlf.txt
warning: LF will be replaced by CRLF in withlf.txt.
The file will have its original line endings in your working directory.
$ ls -la
total 10
d---------+ 1 Stefan None 0 Jan 23 02:12 .
d---------+ 1 Stefan None 0 Jan 23 02:10 ..
d---------+ 1 Stefan None 0 Jan 23 02:22 .git
----------+ 1 Stefan None 3 Jan 23 01:55 withcrlf.txt
----------+ 1 Stefan None 2 Jan 23 01:55 withlf.txt

-- So no changes (see file size) to files in working directory. This is expected and according to output warning from add and commit.

-- Now lets look in the repository

$ git ls-tree -l HEAD withcrlf.txt 100644 blob d00491fd7e5bb6fa28c517a0bb32b8b506539d4d 2 withcrlf.txt $ git ls-tree -l HEAD withlf.txt 100644 blob d00491fd7e5bb6fa28c517a0bb32b8b506539d4d 2 withlf.txt

-- Note that size of withlf.txt is 2 in repository indicating that LF was not replaced by CRLF in withlf.txt as indicated in output from add and commit. Also note that size of withcrlf.txt is also 2 in repository so it looks like CRLF was replaced by LF in withcrlf.txt. To verify I will delete the files from working directory, turn off EOL conversion, checkout files and look at file endings in the working directory.

$ rm with* $ ls -la total 8 d---------+ 1 Stefan None 0 Jan 23 02:31 . d---------+ 1 Stefan None 0 Jan 23 02:10 .. d---------+ 1 Stefan None 0 Jan 23 02:22 .git $ git status # On branch master # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: withcrlf.txt # deleted: withlf.txt # no changes added to commit (use "git add" and/or "git commit -a") $ git config --global core.autocrlf false $ git config --global core.autocrlf false $ git checkout -- with* $ ls -la total 10 d---------+ 1 Stefan None 0 Jan 23 02:38 . d---------+ 1 Stefan None 0 Jan 23 02:10 .. d---------+ 1 Stefan None 0 Jan 23 02:38 .git ----------+ 1 Stefan None 2 Jan 23 02:38 withcrlf.txt ----------+ 1 Stefan None 2 Jan 23 02:38 withlf.txt

-- Both files in working directory files now have LF line endings confirming that files in repository have LF file endings. Either the output message of add and commit is wrong or the behavior of the EOL conversion is wrong... or... have I missed something...?

   /Stefan
Next: Philip Oakley
Message 1 of 6 in “Bug in EOL conversion?”
  1. Stefan NorgrenJan 23, 2013
  2. Philip OakleyJan 23, 2013
  3. Erik Faye-LundJan 23, 2013
  4. Philip OakleyJan 23, 2013
  5. Pēteris KļaviņšJan 23, 2013
  6. Thomas RastJan 23, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.