在Windows中使用Git,希望通过一次提交将可执行的shell脚本gitrepo。
通常需要做两个步骤(git commit
)。
$ vi install.sh $ git add install.sh $ git commit -am "add new file for installation" # first commit [master f2e92da] add support for install.sh 1 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 install.sh $ git update-index --chmod=+x install.sh $ git commit -am "update file permission" # second commit [master 317ba0c] update file permission 0 files changed mode change 100644 => 100755 install.sh
如何将这两个步骤合并成一个步骤?Git配置?Windows命令?
可以尝试下如下代码:
git add --chmod=+x -- afile git commit -m"Executable!"
不需要在两次提交中完成此操作,可以添加文件并在单个提交中标记它为可执行文件:
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
添加后,模式是0644(即,不可执行)。但是,我们可以在提交之前将其标记为可执行文件:
C:\Temp\TestRepo>git update-index --chmod=+x foo.sh C:\Temp\TestRepo>git ls-files --stage 100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 foo.sh
现在文件是模式0755(可执行文件)。
C:\Temp\TestRepo>git commit -m"Executable!" [master (root-commit) 1f7a57a] Executable! 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100755 foo.sh
现在,就有了一个单独的提交文件和一个可执行文件。
有话要说