关于git:如何在github chmod = x中制作上传的文件?然后使用wget命令下载文件,以保留github模式下的可执行文件集?

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?

我的操作系统是Ubuntu 20.04

我已经阅读了这篇文章如何在GIT中向文件添加chmod权限?

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

我正在寻找的是

chmod +x,这样一旦我通过该链接下载文件wget https://raw.githubusercontent.com/PRATAP-KUMAR/focalgdm3/master/focalgdm3即可在Ubuntu 20.04中执行。

我尝试了git update-index命令,但遇到了错误..

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

正在逐步查找程序。.


I have added the file to github by dragging the file from my computer to github upload existing file page.

然后在本地克隆存储库:

1
2
3
4
5
6
cd /path/to/local/clone
git add --chmod=+x myFile
git config --global user.name"My name"
git config --global user.email"[email protected]" (the one used for GitHub account)
git commit -m"Made myFile executable"
git push

如Antwane的答案所述,通过HTTP的wget无法正常工作。
但是,如从"从GitHub下载可执行脚本以保留x权限"所见,您可以:

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

即:

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

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

替换<repo>

在您的情况下:

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


据我了解,您希望使用wget下载可执行文件后可以立即运行该可执行文件。像这样的东西:

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

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

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

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

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


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

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