1

I am developing on 2 computers (windows laptop and linux desktop) and when I check in files on linux with permissions 755 (=executable) and then check them out on Windows, Windows changes the permissions to 644 (removes executable) and I cannot change them back.

When I check in changes, git on windows always wants to check in the new permissions. Changing the permissions with git update-index --chmod=+x script.sh does not work. Git just ignores the command. And it gets really annoying when there are changes I want to pull, because git complains I should commit the file permission changes first before pulling the changes but I don't want to commit them. And checking out the files again doesn't help either because they are immediately changed.

git pull
...
mode change 100644 => 100755 build_apk.sh

git diff
diff --git a/build_apk.sh b/build_apk.sh
old mode 100755
new mode 100644

git update-index --chmod=+x build_apk.sh

git diff
diff --git a/build_apk.sh b/build_apk.sh
old mode 100755
new mode 100644

git status
On branch main
Your branch is up to date with 'origin/main'.

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:   build_apk.sh

How can I tell git on Windows to ignore permission changes on certain files?

GenError
  • 885
  • 9
  • 25

1 Answers1

1

I can't reproduce your problem with a default setup.

Checking out a repo on linux, and adding an executable file:

bp@fischer:~$ git clone https://gitlab.com/thebjorn/bpsettings.git
Cloning into 'bpsettings'...
...
Unpacking objects: 100% (6/6), 552 bytes | 276.00 KiB/s, done.
bp@fischer:~$ cd bpsettings/
bp@fischer:~/bpsettings$ ls -l
total 16
drwxrwxr-x  3 bp dkadm 4096 Sep 29 10:25 ./
drwxr-xr-x 17 bp dkadm 4096 Sep 29 10:25 ../
drwxrwxr-x  8 bp dkadm 4096 Sep 29 10:25 .git/
-rw-rw-r--  1 bp dkadm  124 Sep 29 10:25 README.md
bp@fischer:~/bpsettings$ touch build_apk.sh
bp@fischer:~/bpsettings$ chmod +x build_apk.sh
bp@fischer:~/bpsettings$ git add build_apk.sh
bp@fischer:~/bpsettings$ git commit -am "executable bit set"
[master a302fdf] executable bit set
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100755 build_apk.sh
bp@fischer:~/bpsettings$ git push
Enumerating objects: 4, done.
Counting objects: 100% (4/4), done.
Delta compression using up to 8 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 283 bytes | 283.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitlab.com/thebjorn/bpsettings.git
   d6a8a13..a302fdf  master -> master

cloning on windows

(dev35) go|c:\srv\tmp> git clone https://gitlab.com/thebjorn/bpsettings.git
Cloning into 'bpsettings'...
remote: Enumerating objects: 9, done.
remote: Counting objects: 100% (9/9), done.
remote: Compressing objects: 100% (5/5), done.
remote: Total 9 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (9/9), done.

(dev35) go|c:\srv\tmp> cd bpsettings

(dev35) go|c:\srv\tmp\bpsettings> ls -l
total 4
-rw-rw-rw-  1 bp 0   0 2021-09-29 10:28 build_apk.sh
-rw-rw-rw-  1 bp 0 124 2021-09-29 10:28 README.md

(I have the gnuwin32 tools installed which gives me the ls command in dos).

The permission bits here are a bit irrelevant since the executable status of a file on windows is not controlled by permissions in the same way as linux.

Changing the executable file and committing:

(dev35) go|c:\srv\tmp\bpsettings> dir > build_apk.sh

(dev35) go|c:\srv\tmp\bpsettings> git st
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 checkout -- <file>..." to discard changes in working directory)

        modified:   build_apk.sh

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

(dev35) go|c:\srv\tmp\bpsettings> git commit -am "changes to file with linux executable bit"
[master 82ebdb2] changes to file with linux executable bit
 1 file changed, 11 insertions(+)

(dev35) go|c:\srv\tmp\bpsettings> git push
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 508 bytes | 254.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitlab.com/thebjorn/bpsettings.git
   a302fdf..82ebdb2  master -> master

(dev35) go|c:\srv\tmp\bpsettings>

Pulling the file on linux

bp@fischer:~/bpsettings$ git pull
remote: Enumerating objects: 5, done.
remote: Counting objects: 100% (5/5), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (3/3), 488 bytes | 488.00 KiB/s, done.
From https://gitlab.com/thebjorn/bpsettings
   a302fdf..82ebdb2  master     -> origin/master
Updating a302fdf..82ebdb2
Fast-forward
 build_apk.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)

bp@fischer:~/bpsettings$ ls -l
total 20
drwxrwxr-x  3 bp dkadm 4096 Sep 29 10:29 ./
drwxr-xr-x 17 bp dkadm 4096 Sep 29 10:29 ../
drwxrwxr-x  8 bp dkadm 4096 Sep 29 10:29 .git/
-rw-rw-r--  1 bp dkadm  124 Sep 29 10:25 README.md
-rwxrwxr-x  1 bp dkadm  391 Sep 29 10:29 build_apk.sh*
bp@fischer:~/bpsettings$

The executable bits are still there...

My umask and git version on linux:

bp@fischer:~/bpsettings$ umask
0002
bp@fischer:~/bpsettings$ git --version
git version 2.25.1

git version and permissions on windows:

(dev35) go|c:\srv\tmp\bpsettings> git --version
git version 2.21.0.windows.1
(dev35) go|c:\srv\tmp\bpsettings> icacls .
. BUILTIN\Administrators:(I)(OI)(CI)(F)
  NT AUTHORITY\SYSTEM:(I)(OI)(CI)(F)
  BUILTIN\Users:(I)(OI)(CI)(RX)
  NT AUTHORITY\Authenticated Users:(I)(M)
  NT AUTHORITY\Authenticated Users:(I)(OI)(CI)(IO)(M)

Successfully processed 1 files; Failed processing 0 files
thebjorn
  • 26,297
  • 11
  • 96
  • 138
  • This answer lists a command line method for getting effective permissions for a user in powershell: https://serverfault.com/questions/1002544/check-effective-permissions-effective-access-from-command-line-windows-ntf – thebjorn Sep 29 '21 at 08:57
  • Thanks for the effort! I made a fresh clone of my repository and the issue is gone. Strange, because I had this behavior in multiple repos over the last months. Seems my repos in windows break after some time. – GenError Sep 29 '21 at 09:26
  • I found the issue: https://stackoverflow.com/questions/1257592/how-do-i-remove-files-saying-old-mode-100755-new-mode-100644-from-unstaged-cha?rq=1 For some reason something changes core.filemode to true and then the issue happens. – GenError Sep 29 '21 at 09:58
  • 1
    Learned something new today :-) Feel free to leave a comment if you figure out what changes core.filemode... – thebjorn Sep 29 '21 at 11:40