1

git status shows one modified file even I did not touch it. I do not have any local changes. It is build server. I tried to revert file and I run whatever I found in documentation

git fetch
git checkout -- .
git reset --hard origin/master
git restore xxx/License.txt

git status always shows

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   xxx/License.txt

no changes added to commit (use "git add" and/or "git commit -a")

Running git diff shows all lines removed and added. VS Code does not show any difference. I assume it is non printable character. Line ending is CRLF. Encoding UTF-8.
How to revert file?
It is Windows computer. Source provider is AWS CodeComit.

zdenko.s
  • 931
  • 1
  • 12
  • 29

1 Answers1

1

Check first your git config core.autocrlf in your local session:

If it is true or input, set it to false.

git config --global core.autocrlf false

Then clone your repository again, and see if the issue persists.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I would like to know what happened, why and how to fix instead of brute force remove. It is related to coworkers changing line ending and file encoding. I changed autocrlf to false. I was thinking that git 1. Removes file from file system 2. Takes original version 3. When saving to file system changes line ending based on autocrlf. This is not the case since I changed autocrlf. Cloned repo settings do not have autocrlf and system wide is used (listed). – zdenko.s Mar 23 '21 at 19:16
  • @zdenko.s Instead of cloning again, you can do a `git add --renormalize .; git restore -- .` (as [explained by torek](https://stackoverflow.com/a/53584041/6309)) – VonC Mar 23 '21 at 20:28
  • This is not solving problem. Lot of new files are added to index (staged). Among them is problematic file. after `git restore -- .` I am where I was. I checked torek's answer. Bullet 2, i already tried. Bullet 3 is done by coworker and now I face tmodified file issue. Cloning repo did solved problem. What is interesting, when I copy file from newly clonned repo, it is shown as modified. It has to do something with autcrl at the time when repo was cloned. – zdenko.s Mar 31 '21 at 11:05
  • @zdenko.s Do you have any .gitattributes files in your repository? – VonC Mar 31 '21 at 11:06
  • Yes. Coworker added `* text=auto; *.ini crlf; *.txt text eol=crlf` – zdenko.s Mar 31 '21 at 11:15
  • @zdenko.s That would explain why a new copied file is shown as modified – VonC Mar 31 '21 at 11:16
  • Newly cloned repo uses autocrlf=false and no problem. Old repo causes problem which was cloned with autocrlf=true autocrlf was changed after cloning. – zdenko.s Mar 31 '21 at 11:17
  • @zdenko.s Agreed. Hence my answer mentioning `git config --global core.autocrlf false` – VonC Mar 31 '21 at 11:18
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/230589/discussion-between-zdenko-s-and-vonc). – zdenko.s Mar 31 '21 at 11:19