目次
使用するシーン
場合によっては、ファイルのアクセス許可の変更をリポジトリに送信する必要があります。たとえば、作成したシェルファイルにはデフォルトで実行権限がありません。ユーザーがウェアハウス内のコードをプルする場合は、コードを実行する前に、パッケージ内のすべてのシェルファイルに実行権限を手動で追加する必要があります。もちろん、ファイルのパーミッションの不器用な手動変更を回避するために、ファイルのパーミッションの変更をリポジトリに直接送信することもできます。
方法1:シェルを使用して権限を変更する
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
方法2: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