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

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

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

21条回答
  •  情歌与酒
    2020-11-22 08:49

    First clone the repo with the -n option, which suppresses the default checkout of all files, and the --depth 1 option, which means it only gets the most recent revision of each file

    git clone -n git://path/to/the_repo.git --depth 1
    

    Then check out just the file you want like so:

    cd the_repo
    git checkout HEAD name_of_file
    

提交回复
热议问题