Git:使用可执行文件

时间:2016-07-15 13:51:52

标签: linux git bash executable gitattributes

我有一个项目,其中有一个function Drawing(varCanvas, varSize, varPrice) { var c = this; this.allow = !1; this.size = varSize; this.$canvas = varCanvas; (.....) this.allow = !0; 文件,一旦被其他人拉出,它必须处于可执行模式。现在,我已经在本地计算机上更改了权限。但是我希望它也可以作为可执行文件推送/拉出,这样其他用户就不必一直运行.sh命令。

我已经了解了两个可能的解决方案:chmod.gitattributes,但我不确定在我的情况下我应该遵循什么。

我已经看到this在这里发帖了,this在那里回答,我在想哪一个更适合我的情况。我希望这个过程能够自动完成,而不是每次都由用户完成。

有什么想法吗?

3 个答案:

答案 0 :(得分:2)

由于您已使用标记了此问题,因此您只需检查该文件即可。现在您已在计算机上对其进行了更改:

% 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

你可以看到该文件实际上是可执行文件:

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

模式100644反映了非可执行文件,模式100755反映了可执行文件,类似于Unix文件权限位。 (如果您将文件另外更改为更改权限,您还会看到更改。)

当您检查此内容并且协作者撤消您的更改时,该文件也将成为可执行文件。

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

注意这依赖于您的系统已正确设置core.filemode。在所有非Windows系统上,此值应设置为true

% git config core.filemode
true

如果由于某种原因,该命令返回false并且您在非Windows计算机上,请运行:

% git config core.filemode true

重新启用它。

答案 1 :(得分:0)

你有没有考虑过Git钩子?

也许这可能是你的解决方案

.git/hooks/post-checkout:

#!/bin/sh
chmod +x script.sh

您可以在此处找到有关Git hooks的更多信息。

答案 2 :(得分:0)

您必须决定哪种适合您。你在上面给出的两种方法是可以接受的,它们几乎相同。

您应该知道如何为可执行文件提供工作权限。在Linux中,真正的方法是&#34; chmod&#34;。你也可以起诉git hooks。为了做正常的方法,我更喜欢这个:

git add file.sh #this could be py file or something
git update-index --chmod=+x file.sh #make it executable
git commit -m "here the commit" #commit it
git push #push it

所以,如果你想以另一种方式做,你应该尝试这个:

#!/usr/bin/bash
chmod +x file.sh

你可以运行它。但是在运行之前,您应该为您的脚本提供工作权限,以便为其他脚本提供工作权限:)

或者您可以动态地提供权限:

su -c 'chmod +x file.sh'

通过这种方式,您应该提供一次工作许可,然后运行。