Windows 上的 Git 文件权限
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6476513/
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
Git file permissions on Windows
提问by Synesso
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 中文件权限的问题,但我仍然有点困惑。我在 GitHub 上有一个从另一个分叉的仓库。合并后,它们应该是相同的。然而:
$ 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.
我试过更改文件权限,但它不会改变差异结果。
回答by dedek
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
我在这里找到了如何在 Windows 上更改权限(也)的解决方案: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>
回答by Corey Henderson
From another question here on stackoverflow: How do I make Git ignore file mode (chmod) changes?
来自 stackoverflow 上的另一个问题: How do I make Git ignore file mode (chmod) changes?
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.
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.
回答by Benoit Blanchon
Handy one-liner for Git Bash:
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
.
它将所有.sh
文件标记为可执行文件。之后,你只需要git commit
.
回答by skiphoppy
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:
如果您使用 Cygwin git(或 Linux git,我也假设),很有可能您的 core.filemode 设置已在 $projdir/.git/config 中的项目级别设置。我发现我必须执行以下操作才能让我的 Cygwin git 和我的 Windows git 在 Windows 文件系统上很好地共存,而不会一直显示不存在的文件模式更改:
- delete the line setting core.filemode in $projdir/.git/config
- in Windows git, run "git config --global core.filemode false"
- 删除 $projdir/.git/config 中的行设置 core.filemode
- 在 Windows git 中,运行“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.
这允许我的 Cygwin git 继续查看通常相关的文件模式更改,同时指示 Windows git 忽略它看到的文件模式更改,这通常是误报。
回答by Sireesh Yarlagadda
First check file permissions using below command.
首先使用以下命令检查文件权限。
git ls-files --stage
Then change permissions. Here "x" represents execute permissions.
然后更改权限。这里“x”代表执行权限。
git update-index --chmod=+x 'scriptname.ext'
Now re-verify the permissions.
现在重新验证权限。
git ls-files --stage
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
如果您使用的是 Windows PC,但部署在 linux 机器上。首先执行以下命令,使其兼容在linux机器上运行
dos2unix scriptname.ext scriptname.ext
dos2unix 脚本名.ext 脚本名.ext
回答by Synesso
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.
我通过更改 Ubuntu 中的文件权限、提交、推送和一切正常来修复它。似乎它不适用于 Windows/NTFS 上的 msysgit。