linux - Git:使用可执行文件

标签 linux git bash executable gitattributes

我有一个项目,其中有一个 .sh 文件,一旦被其他人 pull ,它就必须处于可执行模式。现在,我已经在我的本地机器上更改了它的权限。但是我希望它也可以作为可执行文件被推送/pull ,这样其他用户就不必一直运行 chmod 命令。

我被告知有两种可能的解决方案:.gitattributesgit update-index --chmod=+x script.sh,但我不确定具体是什么考虑到我的情况,我应该遵循吗?

我看过 this在这里张贴和this在那里回答,我在想哪个更适合我的情况。我希望这个过程自动完成,而不是每次都由用户完成,添加。

有什么想法吗?

最佳答案

因为你用 标记了这个问题,您只需 checkin 文件即可。现在您已经在计算机上更改了它:

% chmod +x script.sh

Git 会注意到文件已更改:

% git status
On branch old2
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   script.sh

你可以通过 diff 查看该文件实际上现在是可执行的:

% git diff foo.sh
diff --git a/foo.sh b/foo.sh
old mode 100644
new mode 100755

Mode 100644 反射(reflect)的是不可执行文件,mode 100755 反射(reflect)的是可执行文件,类似于Unix文件权限位。 (如果除了更改权限之外还更改了文件,您也会看到更改。)

当您 checkin 此文件并且您的协作者 pull 您的更改时,该文件也将为他们提供可执行文件。


请注意,这不会在没有执行位概念的系统(即 Windows)上自动工作,在那种情况下,您需要做something with update-index .

请注意,这取决于您的系统是否正确设置了 core.filemode。在所有非 Windows 系统上,此值应设置为 true

% git config core.filemode
true

如果出于某种原因,该命令返回 false 并且您使用的是非 Windows 计算机,请运行:

% git config core.filemode true

重新启用它。

关于linux - Git:使用可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38397841/

相关文章:

linux - 是否可以使用 TCP 套接字处理 TCP 标志?

python - 使用 awk/sed/bash 切割 python 输出

c - linux机制测量进程内存消耗f

android - 当前目录上的符号链接(symbolic link)级别太多?

linux - Unix 命令将用户添加到允许 SSH 访问的允许用户列表?

linux - 从 4 个十六进制数字生成 'unique' 3 个字符的标签

linux - 如何将程序打印到单独的窗口(shell/tty)

javascript - Heroku + Node : Cannot find module error

git - 巡航控制和 Git : "Source control operation has timed out." error

linux - 是否可以创建一个始终以 root 身份启动程序的 shell 脚本?不管是谁在运行它