首页 > 解决方案 > 如何在 github chmod=+x 中制作上传文件?然后使用 wget 命令下载文件,保留 github 模式下的可执行文件集?

问题描述

我的操作系统是 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:~$ 

正在寻找一步一步的过程..

标签: gitchmod

解决方案


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

然后克隆存储库,并在本地克隆:

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

正如Antwane回答中所解释的,通过 HTTP 的 wget 将不起作用。
但是从“从 GitHub 下载可执行脚本保留 +x 权限”中可以看出,您可以:

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

那是:

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

替换<user>为您的 GitHub 用户名,<repo>以及您的存储库名称

在你的情况下:

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

推荐阅读