長話短說,今天介紹如何在windows上使用Git上創建一個可執行的shell腳本。
首先我們要知道windows上Git新添加的文件權限是:-rw-r--r--(對應權限值是644),而通常創建的shell腳本都希望天然可執行,故有必要在Windows上使用Git管理shell腳本時保證可執行權限。
早期姿勢(一次Git Commit):
C:\Temp\TestRepo>touch foo.sh
C:\Temp\TestRepo>git add foo.sh
C:\Temp\TestRepo>git ls-files --stage
100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 foo.sh
C:\Temp\TestRepo>git update-index --chmod=+x foo.sh
C:\Temp\TestRepo>git commit -m"Executable!"
[master (root-commit) 1f7a57a] Executable!
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100755 foo.sh
參考上圖,我們在索引區覆蓋文件的可執行位。
最新正統姿勢:從Git 2.9開始,您可以在add命令中暫存文件並設置可執行標志:
git add --chmod=+x path/to/file