Updating file permissions with git-bash on Windows 7

江枫思渺然 提交于 2019-12-17 22:45:29

问题


How do I update file permissions with git-bash on Windows 7?

I've tried the following without success:

$ ls -al scripts/script.sh
-rw-r--r--    1 myUid   Administ       70 Sep  8 11:24 scripts/script.sh

$ git update-index --chmod=+x scripts/script.sh

$ ls -al scripts/script.sh
-rw-r--r--    1 myUid   Administ       70 Sep  8 11:24 scripts/script.sh

$ chmod +x scripts/script.sh

$ ls -al scripts/script.sh
-rw-r--r--    1 myUid   Administ       70 Sep  8 11:24 scripts/script.sh

回答1:


You are probably using NTFS or FAT32 on Windows, and those filesystems do not support the executable permission. Instead, cygwin looks at the file name and contents to determine whether it's executable:

Files are considered to be executable if the filename ends with .bat, .com or .exe, or if its content starts with #!.

So you should make sure that the bash file starts with a shebang (e.g. #!/bin/bash). Then, you should be able to just execute the file, disregarding the permission output of ls.




回答2:


If you're updating scripts in a windows environment that are being deployed to a linux filesystem, even though they are permitted to run locally, you may still find yourself needing to grant execute before pushing.

From this article on Change file permissions when working with git repo's on windows:

  1. Open up a bash terminal like git-bash on Windows
  2. Navigate to the .sh file where you want to grant execute permissions
  3. Check the existing permissions with the following command:

    git ls-files --stage 
    

    Which should return something like 100644

  4. Update the permissions with the following command

    git update-index --chmod=+x 'name-of-shell-script'
    
  5. Check the file permission again

    git ls-files --stage 
    

    Which should return something like 100755

  6. Commit changes and push!



来源:https://stackoverflow.com/questions/25730041/updating-file-permissions-with-git-bash-on-windows-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!