社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Git

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

Depp_Wang • 4 年前 • 151 次点击  
阅读 31

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

作者:DeppWang原文地址

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

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

假设 GitHub 文件的原 URL 是:

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

将其更改为:

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

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

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

原理

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

其他示例: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自动发布

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/56979
 
151 次点击