From:http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/

If there is one thing I miss about SVN having switched to git (and trust me, it’s the only thing), it is the ability to checkout only a sub-tree of a repository. As of version 1.7, you can check out just a sub-tree in git as well! Now not only does git support checking out sub-directories, it does it better than subversion!

New Repository

There is a bit of a catch-22 when doing a sub-tree checkout for a new repository. In order to only checkout a sub-tree, you’ll need to have the core.sparsecheckout option set to true. Of course, you need to have a git repository before you can enable sparse-checkout. So, rather than doing a git clone, you’ll need to start with git init.

  1. Create and initialize your new repository:

    mkdir <repo> && cd <repo>
    git init
    git remote add –f <name> <url>
  2. Enable sparse-checkout:

    git config core.sparsecheckout true
  3. Configure sparse-checkout by listing your desired sub-trees in .git/info/sparse-checkout:

    echo some/dir/ >> .git/info/sparse-checkout
    echo another/sub/tree >> .git/info/sparse-checkout
  4. Checkout from the remote:

    git pull <remote> <branch>

Existing Repository

If you already have a repository, simply enable and configure sparse-checkout as above and do git read-tree.

  1. Enable sparse-checkout:

    git config core.sparsecheckout true
  2. Configure sparse-checkout by listing your desired sub-trees in .git/info/sparse-checkout:

    echo some/dir/ >> .git/info/sparse-checkout
    echo another/sub/tree >> .git/info/sparse-checkout
  3. Update your working tree:

    git read-tree -mu HEAD

Modifying sparse-checkout sub-trees

If you later decide to change which directories you would like checked out, simply edit the sparse-checkout file and run git read-tree again as above.

Be sure to read the documentation on read-tree/sparse-checkout. The sparse-tree file accepts file patterns similar to .gitignore. It also accepts negations—enabling you to specify certain directories or files to not checkout.

Now there isn’t anything that svn does better than git!

最新文章

  1. C#图像处理笔记
  2. python学习心得第五章
  3. curl 或 file_get_contents 获取需要授权页面的方法
  4. Plugins
  5. springmvc web-info目录下无法引入的js文件无效
  6. UVA11538 - Chess Queen(数学组合)
  7. GNU glibc
  8. Hibernate一级缓存、二级缓存
  9. [转]iOS Assembly Tutorial: Understanding ARM
  10. MySQL快速入门 基本技能篇
  11. DialogFragment的应用
  12. Spring源码阅读-spring启动
  13. 单链表创建、删除、查找、插入之C语言实现
  14. 【TCP/IP 协议】 TCP/IP 基础
  15. React Native小白入门学习路径——四
  16. 使用docker部署ambari的若干要点
  17. webpack对多个模块依赖进行打包
  18. 更改backend
  19. JQuery中$.ajax()方法参数详解 转载
  20. ASP.NET MVC5 新特性:Attribute路由使用详解

热门文章

  1. mac下svn无法上传.a文件的问题
  2. (最大上升子序列) Super Jumping! Jumping! Jumping! -- hdu -- 1087
  3. Java IO流详尽解析(转)
  4. java实现WC项目
  5. Team Foundation Server (TFS)与Project Server集成,使用DNS(友好地址)地址注册PWA
  6. OpenDiscussion_DataDrivenDesign
  7. 关于linq的几个小例子
  8. ASP.NET Core 2 学习笔记(二)生命周期
  9. Oracle树结构查询按层级排序
  10. 程序媛计划——python初级class5~13