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

git checkout-index --all --force does not restore all files when `core.autocrlf` is set to `input`

From
Anthony Sottile <asottile@umich.edu>
Date
Jul 31, 2017, 17:01 UTC
Message-ID
<CA+dzEB=aC9RMOMyTGuMiboZ4OrreKQQwoOL0PXckodSfS=Xoog@mail.gmail.com>
I'm not sure if this is a bug or the intended behaviour.

Here's my minimal reproduction (using python3 to write files so I can control line endings)

``` #!/bin/bash set -ex

rm -rf repo git init repo cd repo

git config --local core.autocrlf input

python3 -c 'open("foo", "wb").write(b"1\r\n2\r\n")' git add foo python3 -c 'open("foo", "wb").write(b"3\r\n4\r\n")'

git checkout-index --all --force echo 'I expect this `git status` to have no modifications' git status ```

Here's the output:
```
+ rm -rf repo
+ git init repo
Initialized empty Git repository in /tmp/foo/repo/.git/
+ cd repo
+ git config --local core.autocrlf input
+ python3 -c 'open("foo", "wb").write(b"1\r\n2\r\n")'
+ git add foo
warning: CRLF will be replaced by LF in foo.
The file will have its original line endings in your working directory.
+ python3 -c 'open("foo", "wb").write(b"3\r\n4\r\n")'
+ git checkout-index --all --force
+ echo 'I expect this `git status` to have no modifications'
I expect this `git status` to have no modifications
+ git status
On branch master
Initial commit
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   foo
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
    modified:   foo
```
In this state, `git diff` and `git diff-index` disagree as well:

``` $ git diff-index --exit-code $(git write-tree) --patch; echo $? 1 $ git diff --exit-code; echo $? 0 ```

I expect the plumbing command `checkout-index -af` to exactly restore the disk state to the index such that `git status`, and `git diff-index` both indicate there are no changes.

Interestingly, `git checkout -- .` does exactly this, but it is a porcelain command and not suitable for scripting. Alternatively, I'm looking for an equivalent to `git checkout -- .` which uses only plumbing commands.

Thanks,
Anthony
Message 1 of 1 in “git checkout-index --all --force does not restore all files when `core.autocrlf` is set to `input`”
  1. Anthony SottileJul 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.