如何从GitHub上托管的远程Git repo中仅下载特定文件夹或目录?

举个GitHub repo的例子:

git@github.com:foobar/Test.git

其目录结构:

Test/
├── foo/ 
│   ├── a.py
│   └── b.py   
└── bar/
    ├── c.py
    └── d.py

我只想下载foo文件夹,而不是克隆整个测试项目。


当前回答

转到DownGit>输入您的URL>下载!

您可以直接下载或从DownGit为任何GitHub公共目录或文件创建下载链接-



您还可以配置下载文件的财产-详细用法。


免责声明:我和提问者陷入了同样的问题,无法找到任何简单的解决方案。因此,我首先开发了这个工具供自己使用,然后为每个人打开它:)

其他回答

转到DownGit>输入您的URL>下载!

您可以直接下载或从DownGit为任何GitHub公共目录或文件创建下载链接-



您还可以配置下载文件的财产-详细用法。


免责声明:我和提问者陷入了同样的问题,无法找到任何简单的解决方案。因此,我首先开发了这个工具供自己使用,然后为每个人打开它:)

将git存储库文件夹下载到当前目录并删除git文件。

#!/bin/sh    

function download_git_folder() {
  repo_url=$1
  branch=$2
  repo_subfolder_path=$3
  
  repo_folder=$(basename $repo_url)
  git init
  git remote add -f origin ${repo_url}
  git config core.sparseCheckout true
  echo "${repo_subfolder_path}" >> .git/info/sparse-checkout
  git pull origin ${branch}
  mv "${repo_subfolder_path}"/* ./

  readarray -td/ root_subfolder <<<"${repo_subfolder_path}"; declare -p root_subfolder;
  rm -rf ./.git ${root_subfolder[0]}
}

用法

download_git_folder "git@github.com:foobar/Test.git" "master" "Test/bar" 

我找到的最简单的方法是如何仅克隆Git存储库的子目录?

我在gitclone命令中添加了-b<branch>--singlebranch以下载特定的分支。所以我使用的命令是:

git clone --depth 1 --single-branch -b <branch> --filter=blob:none --sparse <url>
git sparse-checkout set <directory>

gitclone--筛选器仅下载所需文件

例如,要仅克隆此存储库的子目录big/所需的对象:https://github.com/cirosantilli/test-git-partial-clone-big-small我可以做到:

git clone --depth 1 --filter=blob:none --sparse \
  https://github.com/cirosantilli/test-git-partial-clone-big-small
cd test-git-partial-clone-big-small
git sparse-checkout set small

--filter选项是与远程协议的更新一起添加的,它确实防止了从服务器下载对象。

我在下面的文章中详细介绍了这一点:如何仅克隆Git存储库的子目录?

2021 1月在git 2.30.0上测试。

只需5步

从这里下载SVN。打开CMD并转到SVN bin目录,如:cd%ProgramFiles%\SlikSvn\bin假设我想下载这个目录URLhttps://github.com/ZeBobo5/Vlc.DotNet/tree/develop/src/Samples代替树/开发或树干的树/主现在启动最后一个命令以下载同一目录中的文件夹。

svn export https://github.com/ZeBobo5/Vlc.DotNet/trunk/src/Samples