使用 git 版本控制仅更新和提交文件的权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10516201/
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-10 13:39:27  来源:igfitidea点击:

Updating and committing only a file's permissions using git version control

git

提问by BreakPhreak

Just turned an some.shfile into an executable (chmod 755 ...), the permissions were updated but not the content. Is there a way to committhe file into git, so that the executable bit will be restored/set on clone/ checkout/ pull?

刚刚将some.sh文件转换为可执行文件 ( chmod 755 ...),权限已更新,但内容未更新。有没有办法将文件提交到 git 中,以便在clone/ checkout/ pull 时恢复/设置可执行位?

Update:how can I track that the new permissions were submitted to github?

更新:如何跟踪新权限已提交给github

回答by Vincent B.

By default, git will update execute file permissions if you change them. It will not change or track any other permissions.

默认情况下,如果您更改它们,git 将更新执行文件权限。它不会更改或跟踪任何其他权限。

If you don't see any changes when modifying execute permission, you probably have a configuration in git which ignore file mode.

如果您在修改执行权限时没有看到任何更改,则您可能在 git 中有一个忽略文件模式的配置。

Look into your project, in the .gitfolder for the configfile and you should see something like this:

查看您的项目,在该.git文件的config文件夹中,您应该看到如下内容:

[core]
    filemode = false

You can either change it to truein your favorite text editor, or run:

您可以true在您喜欢的文本编辑器中将其更改为,或运行:

git config core.filemode true

Then, you should be able to commit normally your files. It will only commit the permission changes.

然后,您应该能够正常提交您的文件。它只会提交权限更改。

回答by ewwink

@fooMonster article worked for me

@fooMonster 文章对我有用

# git ls-tree HEAD
100644 blob 55c0287d4ef21f15b97eb1f107451b88b479bffe    script.sh

As you can see the file has 644 permission (ignoring the 100). We would like to change it to 755:

如您所见,该文件具有 644 权限(忽略 100)。我们想把它改成 755:

# git update-index --chmod=+x script.sh

commit the changes

提交更改

# git commit -m "Changing file permissions"
[master 77b171e] Changing file permissions
0 files changed, 0 insertions(+), 0 deletions(-)
mode change 100644 => 100755 script.sh

回答by Otheus

Not working for me.

不对我来说有效。

The mode is true, the file perms have been changed, but git says there's no work to do.

模式为真,文件权限已更改,但git说没有工作要做。

git init
git add dir/file
chmod 440 dir/file
git commit -a

The problem seems to be that git recognizes only certain permission changes.

问题似乎是 git 只识别某些权限更改。