Heim  >  Fragen und Antworten  >  Hauptteil

git 如何克隆或下载一个仓库子文件夹?

整个仓库很庞大,只对其中的一个字文件夹感兴趣,不想将整个项目仓库全都克隆下来。

某草草某草草2727 Tage vor921

Antworte allen(3)Ich werde antworten

  • PHPz

    PHPz2017-05-02 09:41:03

    git 存储文件的方式和 CVS/SVN 不同,当你 clone 一个 git 仓库时,你 clone 的是该仓库全部的数据,而不是仅仅 clone 你目前所需要的几个文件。

    Git 1.7.9.5 之后的版本允许导出远端仓库的单个文件,如

    git archive --remote=ssh://host/pathto/repo.git HEAD README.md # 导出 README.md 这个文件

    如果你之前已进行过 clone 操作且你需要的文件在提交历史中,可以使用 git log 命令查到该 commit 的 hash 值然后执行以下命令:

    git checkout hash-id path-to-file

    特别的,如果你的代码是公开项目,也可以这样操作:

    适用于 Coding

    wget https://coding.net/u/user/p/project/git/raw/master/README

    适用于 GitHub

    wget https://raw.githubusercontent.com/user/project/master/README

    Antwort
    0
  • PHPz

    PHPz2017-05-02 09:41:03

    我的解决方法:
    以https://github.com/geekhac/to...子目录为例:

    git init todomvc && cd todomvc

    git config core.sparsecheckout true //设置允许克隆子目录

    echo '/examples/react/*' >> .git/info/sparse-checkout //设置要克隆的仓库的子目录路径

    git remote add origin https://github.com/geekhac/to...

    git pull origin master

    Antwort
    0
  • PHP中文网

    PHP中文网2017-05-02 09:41:03

    进入你感兴趣的文件夹,执行git init初始化这个文件,在clone到你们本地

    Antwort
    0
  • StornierenAntwort