我希望从此链接中下载mysite文件夹: https://github.com/username/repository/master/
我希望从此链接中下载mysite文件夹: https://github.com/username/repository/master/
您能够从GitHub下载一个文件/文件夹
只需要使用:svn export <repo>/trunk/<folder>
例如:svn export https://github.com/lodash/lodash/trunk/docs
注意:您可以首先在终端中列出文件夹的内容,使用命令:svn ls <repo>/trunk/folder
(是的,在2016年,您似乎仍然需要SVN才能简单地下载一些GitHub文件)
master
分支需要使用<repo>/branches/<branch_name>/<folder>
之外,其他都完美无误。 - coreyward<repo>/tags/<tag_name>/<folder>
似乎也可以工作。 - skubetar
命令检索指定文件夹。
curl https://codeload.github.com/[owner]/[repo]/tar.gz/master | \ tar -xz --strip=2 [repo]-master/[folder_path]
例如,
如果您想要从zeit/next.js下载examples/with-apollo/文件夹,您可以输入以下内容:
curl https://codeload.github.com/zeit/next.js/tar.gz/master | \
tar -xz --strip=2 next.js-master/examples/with-apollo
wget -O - https://github.com/zeit/next.js/archive/master.tar.gz | tar -xz --strip=2 "next.js-master/examples/with-apollo"
。 - Noam Manoswget -c https://github.com/user/project/archive/master.zip
- Nick Dong使用GitZip在线工具。它可以将GitHub存储库的子目录作为zip文件下载。无需使用git命令!
以下是一个合适的解决方案,来自于这篇帖子:
创建一个目录
mkdir github-project-name
cd github-project-name
建立一个Git仓库
git init
git remote add origin <URL-link of the repo>
配置您的 git 仓库,只下载特定目录
git config core.sparseCheckout true # enable this
设置您想要下载的文件夹,例如,您只希望从 https://github.com/project-tree/master/doc
下载 doc 目录。 echo "/absolute/path/to/folder" > .git/info/sparse-checkout
例如,如果您只想从主仓库 https://github.com/project-tree/master/doc
下载 doc 目录,则您的命令是 echo "doc" > .git/info/sparse-checkout
。
按照通常的方式下载您的仓库。
git pull origin master
git pull origin
的详细输出中看到,这样做会下载整个代码库;但仅保留在 .git/info/sparse-checkout
中指定的文件夹。使用 https://downgit.github.io/
可以帮助我完成此操作。 - Naveen Reddy Marthala有一个名为 Download ZIP
的按钮。如果您想进行稀疏检出,网站上有许多解决方案可供选择,例如这里。
git
从存储库下载子文件夹。无论如何,托管站点 github.com 没有提供不使用任何外部工具就能这样做的方法。 - IamK如果您和我一样,想要从浏览器中下载github存储库中的文件夹,而不需要任何第三方工具,您可以使用Github的vs code扩展程序。
步骤 1 打开您想要在浏览器中下载的存储库的目录。
步骤 2 在URL栏中将.com
替换为.dev
。例如:https://github.com/lodash/lodash
将变成https://github.dev/lodash/lodash
。
步骤 3 这将打开该Git存储库的VSCode界面。只需右键单击要下载的文件夹,然后选择“下载”选项即可。
curl -sSLfo ./fetch \
https://github.com/gruntwork-io/fetch/releases/download/v0.3.12/fetch_linux_amd64
chmod +x ./fetch
./fetch --repo="https://github.com/foo/bar" --tag="${VERSION}" --source-path="/baz" /tmp/baz
还有一个不错的浏览器扩展,可以下载文件或文件夹
Enhanced-github Google Chrome 浏览器扩展
Enhanced-github MS Edge 浏览器扩展
这可能不是最高效的解决方案,但我觉得很有趣!这个脚本可以只用bash下载github文件夹中的所有文件。
(我曾用它来下载postgresql教程中的文件,但在其他地方未进行过测试)
curl "https://github.com/postgres/postgres/tree/master/src/tutorial" > test.html
links=$(cat test.html | grep -o \[^\"\]\*/blob/\[^\"]\*)
echo $links
echo "Now as a list.."
as_list=($links)
for (( i=0; i<${#as_list[@]}; i++ ));do
download_link=("https://raw.githubusercontent.com${as_list[$i]}")
echo "completing link: "
echo "${download_link///blob/""}"
wget "${download_link///blob/""}"
done
说明:
(1) 第一行代码将目标文件夹下载为html格式,并保存为test.html
(2) 第二行代码提取页面上所有文件链接。这是通过观察到文件链接看起来像“/ postgres / postgres / blob / master / src / tutorial / .gitignore”在html中,我们可以通过查找'blob'并获取每侧最近引号“之间的所有文本来获得所有这些文本
(3) 我们将其转换为列表
(4) 完成任务的方法是观察到文件的原始文本版本的URL略有不同,例如对于URL“/ postgres / postgres / blob / master / src / tutorial / .gitignore”,文件的原始文本URL为“https://raw.githubusercontent.com/postgres/postgres/master/src/tutorial/.gitignore”。因此,为了处理数据,我们将“/ postgres / postgres / blob / master / src / tutorial / .gitignore”转换为“/ postgres / postgres / master / src / tutorial / .gitignore”,最终转换为“https://raw.githubusercontent.com/postgres/postgres/master/src/tutorial/.gitignore”
P.S. 如果我的bash脚本很笨拙 - 我是一个新的Linux用户