Git 修改文件权限

目录

使用场景

方法一:使用shell修改权限

方法二:使用Git命令修改权限


使用场景

有时会涉及到将文件权限的修改提交到版本库中。例如我们创建的shell文件默认情况下是没有执行权限的,如果使用者拉取了仓库中的代码,在执行代码前需要手动的将包中的所有shell文件添加执行权限。当然我们也可以直接将文件权限的修改提交到版本库中,避免笨拙的手动修改文件权限。

 

方法一:使用shell修改权限

使用chmod命令将文件修改好权限后提交到版本库中。

$ ll
total 16
drwxr-xr-x    7 liushuochen  staff   224  1 10 11:15 ./
drwxr-xr-x+ 125 liushuochen  staff  4000  1 10 11:33 ../
drwxr-xr-x   12 liushuochen  staff   384  1 10 11:15 .git/
drwxr-xr-x    3 liushuochen  staff    96 12  6 20:15 conf/
-rw-r--r--    1 liushuochen  staff     0 11 15 15:08 readme.md
-rw-r--r--    1 liushuochen  staff    19  1  9 22:39 tool.sh
-rw-r--r--    1 liushuochen  staff    34  1 10 11:15 tool2.sh

$ chmod 777 tool.sh

$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   tool.sh

no changes added to commit (use "git add" and/or "git commit -a")

$ git add tool.sh

$ git commit -m "modify tool.sh"
[master c028e04] modify tool.sh
 1 file changed, 0 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 tool.sh

方法二:使用Git命令修改权限

在Windows上是通过使用Git命令给文件增加或撤销执行权限。使用 git update-index --chmod=+x <file> 增加文件的执行权限,使用git update-index --chmod=-x <file>撤销文件的执行权限。

git update-index --chmod=+x tool2.sh

git commit -am "revise permission access"
[master e5b2b16] revise permission access
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100755 tool2.sh

猜你喜欢

转载自blog.csdn.net/TCatTime/article/details/112425717
今日推荐