1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Git】リポジトリに登録するファイルに実行権限を与える

Posted at

はじめに

Dockerコンテナの起動時に実行したいシェルスクリプトファイル(.sh)をGitリポジトリに上げて、それをクローンした開発者が実行すると権限の問題で実行できないということがありました。

よく考えたら当然のことなのですが、今までこのような経験がなかったのでメモに残します。

.shファイルの権限

言うまでもありませんが、リポジトリをクローンした開発者には.shファイルの実行権限がないため、Dockerコンテナの起動時にエラーとなります。

そのため、Gitリポジトリ上にファイルを追加する際は.shファイルの権限を明示的に付与してあげないといけません。

実現する方法としては下記の2種類があります。

  • git update-index --chmod=+x path/to/file
  • git add --chmod=+x path/to/file

通常 git addしたファイルは GitHubのInternal Storage上で10644で管理されているが、上記のコマンドを実行すると10755で登録されます。

上記の登録状況は git ls-files --stage コマンドで確認することが可能です。

$ git ls-files --stage

100644 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0 README.md
100755 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 0 sample.sh

参考資料

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?