我在Windows中使用Git,并希望通过一次提交将可执行shell脚本推送到git repo.
通常我需要做两个步骤(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
Run Code Online (Sandbox Code Playgroud)
如何将这两个步骤合并为一步?git配置?Windows命令?
提醒:两个答案都很好,git add --chmod=+x file新git版本支持
参考:在Windows上的Git文件权限中查看第二次提交的问题
Edw*_*son 490
在两次提交中无需执行此操作,您可以添加文件并在单次提交中将其标记为可执行文件:
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
Run Code Online (Sandbox Code Playgroud)
如您所知,添加后,模式为0644(即不可执行).但是,我们可以在提交之前将其标记为可执行文件:
C:\Temp\TestRepo>git update-index --chmod=+x foo.sh
C:\Temp\TestRepo>git ls-files --stage
100755 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 foo.sh
Run Code Online (Sandbox Code Playgroud)
现在该文件是模式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
Run Code Online (Sandbox Code Playgroud)
现在我们只有一个提交单个可执行文件.
Von*_*onC 119
事实上,如果
git-add有--mode一面旗帜会很好
git 2.9.x/2.10(2016年第3季度)实际上将允许(感谢Edward Thomson):
git add --chmod=+x -- afile
git commit -m"Executable!"
Run Code Online (Sandbox Code Playgroud)
这使得所有过程更快,即使core.filemode设置为false也能正常工作.
请参阅Edward Thomson()提交的4e55ed3(2016年5月31日).
帮助:Johannes Schindelin().(由Junio C Hamano合并- -在提交c8b080a,2016年7月6日)ethomsondscho
gitster
add:添加--chmod=+x/--chmod=-x选项可执行位不会被检测到(因此不会设置),用于与存储库的路径
core.filemode设置为false,虽然用户仍然可能希望添加文件作为可执行文件与谁其他用户的兼容性做有core.filemode功能.
例如,添加shell脚本的Windows用户可能希望将它们添加为可执行文件,以便与非Windows上的用户兼容.虽然这可以通过管道命令(
git update-index --add --chmod=+x foo)完成,但是教授该git-add命令允许用户使用他们已经熟悉的命令设置文件可执行文件.
Boh*_*ian 17
如果文件已经设置了+ x标志,git update-index --chmod=+x那么什么都不做,git认为没有什么可以提交,即使标志没有保存到repo中.
您必须首先删除该标志,运行git命令,然后将标志放回:
chmod -x <file>
git update-index --chmod=+x <file>
chmod +x <file>
Run Code Online (Sandbox Code Playgroud)
然后 git看到一个更改,并允许您提交更改.
khi*_*eoy 17
我的 cmd.exe 中没有touchandchmod命令,对我git update-index --chmod=+x foo.sh不起作用。
我终于通过设置skip-worktree位来解决它:
git update-index --skip-worktree --chmod=+x foo.sh
Run Code Online (Sandbox Code Playgroud)
Aka*_*ph7 10
为了让这个对我有用,我必须做的是:
git add --chmod=+x foo.shgit commit -m"Executable!"注意事项是,首先必须确保在config git文件中filemode设置为false,或使用以下命令:
git config core.filemode false
Run Code Online (Sandbox Code Playgroud)
然后您可以使用以下命令设置0777权限:
git update-index --chmod=+x foo.sh
Run Code Online (Sandbox Code Playgroud)