从GitHub repo下载单个文件有哪些技巧?

我不想要显示原始文件的URL;对于二进制文件,什么都没有。

http://support.github.com/discussions/feature-requests/41-download-single-file

是否有可能将GitHub用作“下载服务器”?

如果我们决定切换到GoogleCode,是否提供了上述功能?

或者开源项目是否有免费托管和VCS?


当前回答

2021,GitHub增加了一项新功能,即在web上打开visual studio代码。只需按句号或周期键即可启动。,当您在任何存储库中时。

因此,要下载任何特定文件,您可以按启动vscode。键,然后它将在vscode中显示存储库的所有文件。在那里,您可以通过右键单击>dowload下载所需的任何文件。

其他回答

这肯定会奏效的。至少在Chrome中。右键单击“原始”图标->将链接另存为。

在github上,打开要下载的文件找到与“Blame”按钮相邻的“Raw”按钮按下键盘上的“Alt”,同时左键单击鼠标该文件将以“.txt”格式自动下载(我就是这样做的)手动将“.txt”扩展名更改为“.csv”扩展名

这对我有用,我希望对你也有用。

转到DownGit-输入您的URL-只需下载

无需安装任何东西或遵循复杂的说明;特别适用于大型源文件。



您可以下载单独的文件和目录作为zip文件,也可以创建下载链接。

免责声明:我是此工具的作者。

可以这样使用curl:

卷曲-OLhttps://raw.githubusercontent.com/<username>/<repo名称>/<branch名称>/path/to/file

O表示curl下载内容L表示卷曲遵循重定向

或者试试这个

const https = require('https');
const fs = require('fs');
const DOMAIN = 'raw.githubusercontent.com';

function writeFile(data, fileName) {
  fs.appendFile(fileName, data.toString(), err => {
    if (err) {
      console.log('error in writing file', err);
    }
  });
}

function EOF(data) {
  console.log('EOF');
}

function getFileName(pathToFile) {
  var result = pathToFile.split('/');
  var splitLength = result.length;
  return result[splitLength - 1];
}
function getFile(branchName, username, repoName, ...pathToFile) {
  pathToFile.forEach(item => {
    const path = `/${username}/${repoName}/${branchName}/${item}`;
    const URL = `${DOMAIN}${path}`;
    const options = {
      hostname: DOMAIN,
      path: path
    };
    var fileName = getFileName(item);

    https
      .get(options, function(res) {
        console.log(res.statusCode);
        /* if file not found */
        if (res.statusCode === 404) {
          console.log('FILE NOT FOUND');
        } else {
          /* if file found */
          res.on('data', data => writeFile(data, fileName));
          res.on('end', data => EOF(data));
        }
      })
      .on('error', function(res) {
        console.log('error in reading URL');
      });
  });
}
getFile('master', 'bansalAyush', 'InstagramClone', '.babelrc', 'README.md');