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

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

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

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

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

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


当前回答

在“桌面中的克隆”的右侧,它显示“下载Zip文件”下载Zip文件提取文件

其他回答

如果您想使用wget从github下载zip文件

wget -O filename.zip https://github.com/downloads/user/repository/filename.zip?raw=true

有关详细信息,请参阅此网站

根据这一要点,您可以使用wget或cURL:

单击GitHub repo中的文件名。单击“原始”以显示文件目录在浏览器中复制URL。在命令行中,运行以下任一命令:wget—无检查证书—内容处置https://URL-from-step3/卷曲-LJOhttps://URL-from-step3/再一个:在RHEL7.6中,运行以下命令:wget公司https://URL-from-step3/--输出文档=FILE_NAME

或者试试这个

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');

若您使用npm,只需运行以下命令行,最后,除了这个github文件,它不会下载任何npm包

npx config-pack https://github.com/facebook/react/blob/main/README.md

有关详细信息,请参阅配置包

这种方法适用于Windows,因为我从未使用过MAC,所以我不知道MAC中的备用密钥是什么,我将在下面提到这些密钥。

让我们来谈谈CSV文件。如果要下载CSV文件:

转到要下载的特定数据集并单击它。您将在数据集的右上方看到“原始”按钮。按“Alt”,然后左键单击“Raw”按钮。整个CSV将下载到您的系统中。

记住,您必须同时按下Alt键并单击鼠标左键。只需单击“原始”按钮即可在浏览器中打开CSV。

我希望这有帮助。