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

Re: Cannot checkout after setting the eol attribute

From
Torsten Bögershausen <tboegi@web.de>
Date
Aug 22, 2017, 19:13 UTC
Message-ID
<20170822191318.GA22118@tor.lan>
In-Reply-To
<20170822174918.GA1005@megas.kitware.com>
On Tue, Aug 22, 2017 at 01:49:18PM -0400, Ben Boeckel wrote:
Show 25 quoted lines
> Hi,
> 
> I specified the `eol` attribute on some files recently and the behavior
> of Git is very strange.
> 
> Here is the set of commands to set up the repository used for the
> discussion:
> 
>     git init
>     echo $'dos\r' > dos
>     git add dos
>     git commit -m "dos newlines"
>     echo "dos -crlf" > .gitattributes
>     git add .gitattributes
>     git commit -m "add attributes"
>     echo "dos eol=crlf" > .gitattributes
>     git add .gitattributes
>     git commit -m "set eol attribute instead"
> 
> The following behaviors are observed:
> 
>   - `git reset --hard` does not make the working directory clean; and
>   - `git rebase` gets *very* confused about the diffs in the working
>     tree because `git stash` can't reset the working tree;
> 
Show 12 quoted lines
> There are probably other oddities lingering about as well. If I commit
> what Git thinks is the difference, the diff (with invisibles made
> visible) is:
> 
>     % git diff | cat -A
>     diff --git a/dos b/dos$
>     index fde2310..4723a1b 100644$
>     --- a/dos$
>     +++ b/dos$
>     @@ -1 +1 @@$
>     -dos^M$
>     +dos$

Thanks for the goos example! This is by design.

When you set the text attribute (in your case "eol=crlf" implies text) then the file(s) -must- be nomalized and commited so that they have LF in the repo (technically speaking the index)

This is what is written about the "eol=crlf" attribute:
	This setting forces Git to normalize line endings for this
	file on checkin and convert them to CRLF when the file is
	checked out.
And this is what is implemented in Git.
Long story short:
The following would solve your problem:
   git init
   echo $'dos\r' > dos
   git add dos
   git commit -m "dos newlines"
   echo "dos -crlf" > .gitattributes
   git add .gitattributes
   git commit -m "add attributes"
   echo "dos eol=crlf" > .gitattributes
   git read-tree --empty   # Clean index, force re-scan of working directory
   git add dos
   git add .gitattributes
   git commit -m "set eol attribute instead"
   git ls-files --eol
> 
> Seen in 2.9.5 and 2.14.0.rc1.
> 
> --Ben
Previous: Ben BoeckelNext: Ben Boeckel
Message 2 of 15 in “Cannot checkout after setting the eol attribute”
  1. Ben BoeckelAug 22, 2017
  2. Torsten BögershausenAug 22, 2017
  3. Ben BoeckelAug 22, 2017
  4. Torsten BögershausenAug 23, 2017
  5. Ben BoeckelAug 23, 2017
  6. Junio C HamanoAug 22, 2017
  7. Documentation: mention that `eol` can change the dirty status of pathsBen Boeckel, Aug 23, 2017
  8. Ben BoeckelAug 23, 2017
  9. Torsten BögershausenAug 24, 2017
  10. Ben BoeckelAug 30, 2017
  11. Junio C HamanoAug 30, 2017
  12. Ben BoeckelAug 31, 2017
  13. Documentation: mention that `eol` can change the dirty status of pathsBen Boeckel, Aug 30, 2017
  14. Documentation: mention that `eol` can change the dirty status of pathsBen Boeckel, Aug 31, 2017
  15. Torsten BögershausenAug 31, 2017

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.