git中sh文件添加可执行权限

227 阅读1分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

背景

有时我们需要在git仓库中放一些可执行脚本,但是部署到线上后却没有可执行权限,还要单独加权限,过程比较繁琐,下面介绍下如果修改git仓库中文件的权限

1.查看文件权限信息

$ git ls-files --stage100644 b0a1909819160a88cf723cba9b082a41638e19d7 0       work.sh

发现644(r=4,w=2,x=1),需要将其修改为可执行权限755

git-ls-files - 显示有关索引和工作树中文件的信息

git update-index --help

语法规则

git ls-files [-z] [-t] [-v] [-f]

(--[cached|deleted|others|ignored|stage|unmerged|killed|modified])*

(-[c|d|o|i|s|u|k|m])*

[--eol]

[-x |--exclude=]

[-X |--exclude-from=]

[--exclude-per-directory=]

[--exclude-standard]

[--error-unmatch] [--with-tree=]

[--full-name] [--recurse-submodules]

[--abbrev] [--] […]

输出格式 [ ]

$ git ls-files --stage100644 b0a1909819160a88cf723cba9b082a41638e19d7 0       work.sh

2.增加可执行权限

git update-index --chmod +x work.sh

查看帮助

git update-index --help

语法规则

git update-index

[--add] [--remove | --force-remove] [--replace]

[--refresh] [-q] [--unmerged] [--ignore-missing]

[(--cacheinfo ,,)…]

[--chmod=(+|-)x]

[--[no-]assume-unchanged]

[--[no-]skip-worktree]

[--[no-]fsmonitor-valid]

[--ignore-submodules]

[--[no-]split-index]

[--[no-|test-|force-]untracked-cache]

[--[no-]fsmonitor]

[--really-refresh] [--unresolve] [--again | -g]

[--info-only] [--index-info]

[-z] [--stdin] [--index-version ]

[--verbose]

[--] […]

--chmod=(+|-)x

Set the execute permissions on the updated files.

3.再次查看文件权限信息

100755 b0a1909819160a88cf723cba9b082a41638e19d7 0       work.sh

www.phpmianshi.com/?id=298