Git file permissions on Windows

WindowsGitDiffFile Permissions

Windows Problem Overview


I've read through a few questions regarding file permissions in Git and I'm still a bit confused. I've got a repo on GitHub forked from another. Post merge, they should be identical. However:

$ git diff --summary origin/epsilon master/epsilon
 mode change 100644 => 100755 ants/dist/sample_bots/csharp/compile.sh
 mode change 100644 => 100755 ants/dist/starter_bots/coffeescript/MyBot.coffee
 mode change 100644 => 100755 ants/dist/starter_bots/coffeescript/ants.coffee
 mode change 100644 => 100755 ants/util/block_test.sh
 mode change 100644 => 100755 manager/mass_skill_update.py
 mode change 100644 => 100755 worker/jailguard.py
 mode change 100644 => 100755 worker/release_stale_jails.py
 mode change 100644 => 100755 worker/start_worker.sh

I've tried changing file permissions, but it does not alter the diff results.

Windows Solutions


Solution 1 - Windows

I found the solution of how to change permissions (also) on Windows here: http://blog.lesc.se/2011/11/how-to-change-file-premissions-in-git.html

For example following command adds user execute permission to an arbitrary file:

git update-index --chmod=+x <file>

Solution 2 - Windows

From another question here on stackoverflow: https://stackoverflow.com/questions/1580596/how-do-i-make-git-ignore-mode-changes-chmod

Try:

git config core.filemode false

From git-config(1):

> core.fileMode If false, the executable bit differences between the index and the working copy are ignored; useful on broken filesystems like FAT. See git-update-index(1). True by default.

Solution 3 - Windows

Handy one-liner for Git Bash:

find . -name '*.sh' | xargs git update-index --chmod=+x

It will mark all .sh file as executable. After that, you just have to git commit.

Solution 4 - Windows

If you use Cygwin git (or Linux git, too, I assume), there's a good chance your core.filemode setting has been set at the project level in $projdir/.git/config . I found that I had to do the following to get my Cygwin git and my Windows git to coexist nicely on a Windows filesystem without nonexistent filemode changes showing up all the time:

  • delete the line setting core.filemode in $projdir/.git/config
  • in Windows git, run "git config --global core.filemode false"

This allows my Cygwin git to continue to see filemode changes, which are usually relevant, while instructing the Windows git to ignore the filemode changes it sees, which are usually false positives.

Solution 5 - Windows

First check file permissions using below command.

git ls-files --stage

Then change permissions. Here "x" represents execute permissions.

git update-index --chmod=+x 'scriptname.ext'

Now re-verify the permissions.

> git ls-files --stage

==============================================

if you are using Windows PC, but deploying on linux machine. Execute the below command in the first place to make it compatible to run on linux machine

dos2unix scriptname.ext scriptname.ext

Solution 6 - Windows

I fixed it by changing the file permissions in Ubuntu, commit, push and all OK. Seems it just wouldn't work with msysgit on Windows/NTFS.

Solution 7 - Windows

In my case, I accidentally shifted the shebang line so that

#! /bin/sh

became

   #! /bin/sh

This fails the git-bash permission check. After removing the leading whitespaces, the script becomes executable again.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSynessoView Question on Stackoverflow
Solution 1 - WindowsdedekView Answer on Stackoverflow
Solution 2 - WindowsCorey HendersonView Answer on Stackoverflow
Solution 3 - WindowsBenoit BlanchonView Answer on Stackoverflow
Solution 4 - WindowsskiphoppyView Answer on Stackoverflow
Solution 5 - WindowsSireesh YarlagaddaView Answer on Stackoverflow
Solution 6 - WindowsSynessoView Answer on Stackoverflow
Solution 7 - WindowskakyoView Answer on Stackoverflow