git 如何更改 GitHub 上的文件模式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9027584/
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
How to change the File Mode on GitHub?
提问by Steven Penny
$ git add test-file
$ git commit -m 'first commit'
create mode 100644 test-file
$ git push
$ git update-index --add --chmod=+x test-file
$ git commit -m 'change mode'
mode change 100644 => 100755 test-file
$ git push
After that if you go to GitHub it still shows as 100644 no matter what.
之后,如果你去 GitHub,无论如何它仍然显示为 100644。
采纳答案by Steven Penny
MSYS is not the problem. Even if MSYS chmod
doesnt work (it doesnt), Git has a built in way of getting around that problem, ie git update-index --chmod=+x
. Let it be clear that git update-index
only messes with the index (staging area), not the local repository (working directory).
MSYS 不是问题。即使 MSYSchmod
不起作用(它不起作用),Git 也有解决该问题的内置方法,即git update-index --chmod=+x
. 明确一点,git update-index
只与索引(暂存区)混淆,而不是本地存储库(工作目录)。
I am convinced the problem is with GitHub. On GitHub if a file is initiallypushed with mode 100775, all is well. If a file is initiallypushed as 100644 it causes a problem. Attempts to change the file mode will succeed with git add
, succeed with git commit
, succeed with git push
, and even show up in the GitHub file history, but notbe reflected on the "blob/master" page on GitHub.
我确信问题出在 GitHub 上。在 GitHub 上,如果文件最初以模式 100775 推送,则一切正常。如果文件最初被推送为 100644,则会导致问题。尝试更改文件模式将成功git add
,成功git commit
,成功git push
,甚至显示在 GitHub 文件历史记录中,但不会反映在GitHub上的“blob/master”页面上。
Update
更新
From: Petros Amiridis (GitHub Staff)
Subject: How to change FIle Mode on GitHub?
I have some good news. Our awesome team has just confirmed it is a caching bug on our end. Our team has deployed a fix.
来自:Petros Amiridis(GitHub 员工)
主题:如何在 GitHub 上更改文件模式?
我有一些好消息。我们出色的团队刚刚确认这是我们端的缓存错误。我们的团队已经部署了一个修复程序。
回答by Keith Thompson
I think the problem is that MSYS, on which the Windows implementation of git is based, doesn't handle chmod
properly.
我认为问题在于git 的 Windows 实现所基于的MSYS没有chmod
正确处理。
(EDIT: The other answer says MSYS is not the problem, which certainly seems plausible.)
(编辑:另一个答案说 MSYS 不是问题,这当然似乎是合理的。)
My guess is that the command
我的猜测是命令
git update-index --add --chmod=+x test-file
works by updating the metadata in the local repository (which should work) and changing the permissions on the file (which doesn't), putting the local repository into an inconsistent state.
通过更新本地存储库中的元数据(应该可以工作)并更改文件的权限(不能)来工作,从而使本地存储库处于不一致状态。
You should be able to back out of this by undoing the update-index
:
您应该能够通过撤消以下操作来退出update-index
:
git update-index --add --chmod=-x test-file
git commit -m 'change mode back'
git push
to get the repository back into a consistent state, and then making the change in a non-Windows copy of the repository. If you don't have access to a Linux or other Unix-like system, Cygwinincludes git
(not by default, but you can install it via setup.exe
) and gives you an environment in which chmod
actually works. The default shell for Cygwin is bash, so the environment should be familiar if you've been using git bash.
使存储库恢复到一致状态,然后在存储库的非 Windows 副本中进行更改。如果您无权访问 Linux 或其他类 Unix 系统,Cygwin包含git
(默认情况下不是,但您可以通过 安装它setup.exe
)并为您提供一个chmod
实际工作的环境。Cygwin 的默认 shell 是 bash,所以如果你一直在使用 git bash,应该熟悉环境。
The file still won't appear to be executable when you look at it from the git bash shell, but it should show up as 100755
in the GitHub web interface.
当您从 git bash shell 查看该文件时,该文件仍然不会显示为可执行文件,但它应该显示为100755
GitHub Web 界面中。