如何直接下载 Github 上的某个文件

做者:DeppWang原文地址git

有时候咱们须要下载别人 GitHub 仓库的某一个文件,可是不得不 clone 整个项目,此时须要一种能直接下载某一个文件的方式。github

只须要更改一下 GitHub 文件 URL,就能实现单个下载功能。web

假设 GitHub 文件的原 URL 是:ruby

https://github.com/DeppWang/Java-Books/blob/master/docs/Algorithms, 4th Edition.pdf
复制代码

将其更改成:bash

https://raw.githubusercontent.com/DeppWang/Java-Books/master/docs/Algorithms, 4th Edition.pdf
复制代码

即,将 github.com 替换为 raw.githubusercontent.com,并去除 /blobapp

这样就能直接下载这个 Algorithms, 4th Edition.pdf 文件了curl

原理

raw.githubusercontent.com 返回存储在 GitHub 中的文件的 raw content(原始内容),所以能够将它们简单地下载到计算机上。能够在网页上右键查看源文件的方式验证文件 URL 是否包含 raw.githubusercontent.comwebapp

其余示例:Install Homebrew测试

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
复制代码

参考

如何让别人直接在线阅读本身 Github 中的 PDF 文件

当 PDF 文件较大时,在 GitHub 中不能直接预览显示。可借助 GitHub 的 GitHub Pages 实现这个功能。网站

GitHub Pages 能够将 repo 转换为可直接在线浏览的网站,这样就能直接在线阅读 repo 里面的 PDF 文件了。

操做步骤以下:

  1. 建立一个名为 USERNAME.github.io 的 repo,至关于你的我的网站。可访问 https://USERNAME.github.io 测试

  1. 返回到你存放文件的项目 repo,在 SettingsGitHub Pages 中选择分支,此操做是将 repo 做为 http://USERNAME.github.io 中的一个文件

image.png

  1. 项目 repo 的 Intro.pdf 在 https://USERNAME.github.io 的连接:
http://USERNAME.github.io/REPONAME/path/Intro.pdf
复制代码
  1. 示例:项目 Java-Books 的 [Algorithms, 4th Edition.pdf](github.com/DeppWang/Ja… 4th Edition.pdf) 在 deppwang.github.io/ 的连接:
https://deppwang.github.io/Java-Books/docs/Algorithms, 4th Edition.pdf
复制代码

参考

使用场景

本篇文章由一文多发平台ArtiPub自动发布

相关文章
相关标签/搜索