下载GitHub上单个文件(夹)

偷节点的时候总是会有之前失效节点,使用这个工具开源下载单个文件夹

方法一:SVN-下载单个文件夹

个人最适应的方法,缺点是需要借助第三方工具-svn

环境:Windows 10

​ 若想要下载{username}{repo}里的{dir}文件夹,

  1. 主分支master(现在似乎默认是main了,区别不大):
    • 其浏览器路径应为https://github.com/{username}/{repo}/tree/master/{dir}
    • 修改/tree/master//trunk/
    • 打开cmd,输入指令:svn checkout https://github.com/{username}/{repo}/trunk/{dir}
    • {dir}将被下载至当前目录下 示例 示例
  2. 特定分支
    • /trunk/换成/branches/{branch_name}即可

方法二:高版本 Git

这个方法较为繁琐,但无需像前者一样借助其它工具

方法:Git 的Sparse Checkout模式,指定文件/文件夹

  1. 创建空的本地仓库,并将远程 Git Server URL 加入到 Git Config里 none
    1
    2
    3
    4
    mkdir project_folder
    cd project_folder
    git init
    git remote add -f origin <repo-url>
  2. Config 中设置允许使用Sparse Checkout模式 none
    1
    git config core.sparsecheckout true
  3. .git/info/目录下新建sparse-checkout文件(注意文件名不要错了),写入需要的文件(一行为一项) 如: none
    1
    2
    /source/tools/index.html
    /source/about
  4. 以正常方式从服务器pull下来即可 none
    1
    git pull origin master

方法三:利用 DownGit 工具