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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25730041/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:26:12  来源:igfitidea点击:

Updating file permissions with git-bash on Windows 7

gitcygwinwindows-7-x64git-bash

提问by blueberryfields

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

如何git-bash在 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

回答by Yogu

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

您可能在 Windows 上使用 NTFS 或 FAT32,而这些文件系统不支持可执行权限。相反,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(e.g. #!/bin/bash). Then, you should be able to just execute the file, disregarding the permission output of ls.

所以你应该确保bash文件以shebang开头(例如#!/bin/bash)。然后,您应该能够只执行该文件,而忽略ls.

回答by KyleMit

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.

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

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
  2. Navigate to the .shfile 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!

  1. 在 Windows 上打开像 git-bash 这样的 bash 终端
  2. 导航到.sh要授予执行权限的文件
  3. 使用以下命令检查现有权限:

    git ls-files --stage 
    

    哪个应该返回类似100644 的内容

  4. 使用以下命令更新权限

    git update-index --chmod=+x 'name-of-shell-script'
    
  5. 再次检查文件权限

    git ls-files --stage 
    

    哪个应该返回类似100755 的内容

  6. 提交更改并推送!

git bash on windows

Windows 上的 git bash