0

I don't get why by doing git checkout filename is not working.

Here are the steps. First, in the terminal:

enter image description here

Now git status:

enter image description here

I get a bunch of files that are modified. When I try with each of those files to checkout them I get this (I'll do an example with only 2 files):

enter image description here

Everything seems fine, but when I do a git status I can see those file again on the modified list:

enter image description here

So, I don't get. The only thing that came in mind is that another exe is reading and writing those files at every moment, but why not other files? I have a lot of files under src/public. This happen too if I restart (Windows) and the very first thing that I try is this (without opening IDE's or whatever) If I delete those files, I will remove the from the branch, I can't do that, I just want to remove them as modified. Any idea?

Edit: My last tries according to @VonC answer were:

274  git restore transpiler.sh
275  git config --global core.autocrlf false
276  git checkout transpiler.sh
277  git restore transpiler.sh
278  git checkout -- transpiler.sh
279  git checkout transpiler.sh
280  git status

still there the file...

pmiranda
  • 7,602
  • 14
  • 72
  • 155

1 Answers1

1

If the issue persists with git restore aFile (which is easier than git checkout -- aFile, to avoid to specify to checkout that aFile is a file, not a branch), then check your configuration

git config core.autocrlf

I prefer making sure it is set to false, to avoid any automatic eol (end-of-line) conversion.
Then try git restore + git status again.


The OP pmiranda points out in the comments to the other cause of automatic change: core.filemode, that I explained here.

Tells Git if the executable bit of files in the working tree is to be honored.

The remedy is:

git config core.filemode false 

This avoids:

old mode 100755 
new mode 100644
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, I will test. `git config core.autocrlf` returns `true`. Didn't work either. How can I set `core.autocrlf` false? – pmiranda Apr 17 '20 at 05:55
  • I put a comment at the end of my question, didn't work with `false` and `restore` – pmiranda Apr 17 '20 at 06:03
  • 1
    @pmiranda Do you have a .gitattributes in your repository? There could be directive changing the content of those files on checkout. – VonC Apr 17 '20 at 07:19
  • no, I don't that file, I have this ones: https://i.imgur.com/Xk48uGk.png ( I can't quote your name) – pmiranda Apr 17 '20 at 16:04
  • 1
    @pmiranda What does a `git diff` return for those two files? – VonC Apr 17 '20 at 19:49
  • `old mode 100755 new mode 100644` for both of them (actually for evey file from the modified list). So, it's a change of permission? what – pmiranda Apr 17 '20 at 23:16
  • Done, I got it with: `git config core.filemode false` from https://stackoverflow.com/a/1257613/3541320 – pmiranda Apr 18 '20 at 02:41
  • @pmiranda This is indeed the second cause for automatic differences when cloning/checkout a repo. I have edited the answer accordingly, with links to past questions where I explain what that "filemode" is. – VonC Apr 18 '20 at 05:54