How to sparsely checkout only one single file from a git repository?

前端 未结 21 1900
Happy的楠姐
Happy的楠姐 2020-11-22 08:14

How do I checkout just one file from a git repo?

21条回答
  •  遥遥无期
    2020-11-22 08:58

    If you need a specific file from a specific branch from a remote Git repository the command is:

    git archive --remote=git://git.example.com/project.git refs/heads/mybranch path/to/myfile |tar xf -
    

    The rest can be derived from @VonC's answer:

    If you need a specific file from the master branch it is:

    git archive --remote=git://git.example.com/project.git HEAD path/to/myfile |tar xf -
    

    If you need a specific file from a tag it is:

    git archive --remote=git://git.example.com/project.git mytag path/to/myfile |tar xf -
    

提交回复
热议问题