【问题标题】:How to make a uploaded file in github chmod=+x? and then download the file with wget command preserving the executable set in github mode?如何在 github chmod=+x 中制作上传文件?然后使用 wget 命令下载文件,保留 github 模式下的可执行文件集?
【发布时间】:2020-06-18 03:59:34
【问题描述】:

我的操作系统是 Ubuntu 20.04

我已经看过这篇帖子How to add chmod permissions to file in GIT?

我拥有的是这个文件https://github.com/PRATAP-KUMAR/focalgdm3/blob/master/focalgdm3

我在看什么

chmod +x 这样一旦我通过这个链接 wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3 从 github 下载文件,它就可以在 Ubuntu 20.04 中执行了

我尝试了git update-index 命令但出现错误..

pratap@i7-6550U:~$ git update-index --chmod=+x focalgdm3fatal: not a git repository (or any of the parent directories): .gitpratap@i7-6550U:~$ 

寻找一步一步的过程..

【问题讨论】:

  • 为什么要跳过我在答案中提到的提交步骤?您不能添加,然后推送。它是git add --chmod=+x focalgdm3,(带有=),然后是git commit -m "executable",然后是git push。如果它不起作用,那只是意味着您已经添加了可执行集。
  • 是的,我已经编辑了答案以包含相关命令以避免该错误消息。
  • 你想要达到的不可能:serverfault.com/questions/863522/…

标签: git chmod


【解决方案1】:

我已通过将文件从我的计算机拖到 github 上传现有文件页面的方式将文件添加到 github。

然后clone the repository,本地:

cd /path/to/local/clone
git add --chmod=+x myFile
git config --global user.name "My name"
git config --global user.email "my@email.com" (the one used for GitHub account)
git commit -m "Made myFile executable"
git push

正如Antwaneanswer 中所述,通过 HTTP 的 wget 将不起作用。
但是从“Download executable script from GitHub preserving +x permissions”可以看出,你可以:

  • 从 GitHub 存储库获取 tarball(无需 Git)
  • 从中提取单个文件:然后应保留其权限。

即:

wget -qO - https://github.com/<user>/repo>/archive/master.tar.gz | \
tar zx --strip-components=1 <repo>-master/<filename>

&lt;user&gt; 替换为您的 GitHub 用户名,将 &lt;repo&gt; 替换为您的存储库名称

在你的情况下:

wget -qO - https://github.com/PRATAP-KUMAR/focalgdm3/archive/master.tar.gz | \
tar zx --strip-components=1 focalgdm3-master/focalgdm3

【讨论】:

【解决方案2】:

在执行git update-index命令之前,请先进入github.com/PRATAP-KUMAR/focalgdm3目录。

$ cd github.com/PRATAP-KUMAR/focalgdm3
$ git update-index --chmod=+x focalgdm3

【讨论】:

  • 您在哪里克隆了focalgdm3 存储库?
  • 你不需要克隆 repo,你的本地 repo 就可以了
【解决方案3】:

据我了解,您希望在使用wget 下载后立即运行可执行文件。类似的东西:

wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3
./focalgdm3

这是不可能的(主要是出于安全原因),因为 HTTP 协议(​​当您从 GitHub 下载文件时使用)没有关于您文件的 RWX 标志的信息(请参阅https://serverfault.com/a/863523/398223

一个可能的解决方案是在您的安装过程中添加chmod 命令

wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3
chmod +x focalgdm3
./focalgdm3

您还可以将您的 focalgdm3 二进制文件放入 zip 或 .tar.gz 存档(保留可执行标志),并将其放入您的 GitHub 存储库,以便您的用户可以下载、提取和运行该程序。

【讨论】:

    猜你喜欢
    • 2021-06-19
    • 1970-01-01
    • 2013-02-12
    • 2013-04-16
    • 2013-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多