简体   繁体   English

在 Windows 7 上使用 git-bash 更新文件权限

[英]Updating file permissions with git-bash on Windows 7

How do I update file permissions with git-bash on Windows 7?如何在 Windows 7 上使用git-bash更新文件权限?

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

You are probably using NTFS or FAT32 on Windows, and those filesystems do not support the executable permission.您可能在 Windows 上使用 NTFS 或 FAT32,而这些文件系统不支持可执行权限。 Instead, cygwin looks at the file name and contents to determine whether it's executable :相反, cygwin 查看文件名和内容以确定它是否可执行

Files are considered to be executable if the filename ends with .bat, .com or .exe, or if its content starts with #!.如果文件名以 .bat、.com 或 .exe 结尾,或者其内容以 #! 开头,则文件被视为可执行文件。

So you should make sure that the bash file starts with a shebang (eg #!/bin/bash ).所以你应该确保bash文件以shebang开头(例如#!/bin/bash )。 Then, you should be able to just execute the file, disregarding the permission output of ls .然后,您应该能够只执行该文件,而忽略ls的权限输出。

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.如果您正在 Windows 环境中更新部署到 linux 文件系统的脚本,即使它们被允许在本地运行,您可能仍然发现自己需要在推送之前授予执行权限。

From this article on Change file permissions when working with git repo's on windows :从这篇关于在 Windows 上使用 git repo 时更改文件权限的文章:

  1. Open up a bash terminal like git-bash on Windows在 Windows 上打开像 git-bash 这样的 bash 终端
  2. Navigate to the .sh file where you want to grant execute permissions导航到要授予执行权限的.sh文件
  3. Check the existing permissions with the following command:使用以下命令检查现有权限:

     git ls-files --stage

    Which should return something like 100644哪个应该返回类似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哪个应该返回类似100755 的内容

  6. Commit changes and push!提交更改并推送!

Windows 上的 git bash

Very likely you do not have "shebang" at the beginning of your script.您的脚本开头很可能没有“shebang”。 So Windows does not know which binary should be used to run the script.所以 Windows 不知道应该使用哪个二进制文件来运行脚本。 Thus the permissions gets silently ignored.因此,权限被默默地忽略。

For example:例如:

#!/usr/bin/sh

or或者

#!/usr/bin/bash

It looks like git-bash detects it automaticly, because the executable attribute gets set even without chmod command.看起来 git-bash 会自动检测到它,因为即使没有 chmod 命令,可执行属性也会被设置。 Moreover it is not possible to disable it by using chmod.此外,无法使用 chmod 禁用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM