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!

[转]Subdirectory Checkouts with git sparse-checkout的更多相关文章

  1. Git sparse checkout

    Git的sparse checkout在clone项目仓库时只clone指定路径下的信息. 步骤如下: (1) mkdir yourdir(2) cd yourdir(3) git init(4) g ...

  2. 使用Sparse Checkout 排除跟踪Git仓库中指定的目录或文件

    应用场景 在一个大工程里包含由不同部门开发的模块时,项目的Git仓库肯定很大,造成每次Git操作相对比较耗时.因为开发人员一般只关心他们部门的模块的代码,所以完全可以排除一些他完全不需要用到的目录.这 ...

  3. git branch & checkout fetch 的使用和冲突解决

    git branch & checkout fetch 的使用和冲突解决 branch git branch 查看本地分支 git branch -v    查看本地分支的具体信息(commi ...

  4. TortoiseSVN 只取下或更新部分文件的方法(Sparse Update/Sparse Checkout)

    Sparse Update/Sparse Checkout   To easily select only the items you want for the checkout and force ...

  5. Git的checkout, reset, revert

    不管是修改还是新建文件,都必须通过git add把这次修改从工作区加到暂存区: commit只是提交暂存区的修改,还没add到暂存区处于工作区的修改是不会commit的:   git checkout ...

  6. 在 Git 中 Checkout 历史版本

    昨天写代码的时候,误删了一个文件.今天发现的时候,commit 已经 push 到版本库了.本想用 git reset 回退版本,找回文件后重新提交.但是想起 Git 是一个版本控制系统哎,直接从版本 ...

  7. Git CMD - checkout: Switch branches or restore working tree files

    命令格式 git checkout [-q] [-f] [-m] [<branch>] git checkout [-q] [-f] [-m] --detach [<branch&g ...

  8. Git单独checkout子目录

    http://schacon.github.io/git/git-read-tree.html#_sparse_checkout Existing Repository If you already ...

  9. git使用中checkout生成临时br的问题(吓出一身冷汗啊)

    git中几天前漫不经心的使用了git checkout ver_hash的命令,结果push到远程库都提示everything is up-to-date,实际神马都没提交上去啊!但看本地log中的确 ...

随机推荐

  1. modelsim读写TXT文件

    //open the file Initial Begin step_file = $fopen("F:/Company/Src/txt/step.v","r" ...

  2. 17)maven-surefire-plugin

    http://maven.apache.org/surefire/maven-surefire-plugin/ Goals Overview The Surefire Plugin has only ...

  3. 【翻译】JavaScript框架的最终指南

    翻译原文链接 我的翻译小站 紧跟JavaScript框架的脚步是一个挑战.现在有太多的框架,几乎一个月就会出来一个新的.那么如何知道到底哪一个比较合适你的项目呢?它们分别有什么优点和缺点呢?你要如何开 ...

  4. springmvc 开涛 注解式控制器

    版本 定义处理器类 处理器映射适配器 备注 支持的注解 2.5前 controller       2.5 注解 DefaultAnnotationHandlerMapping AnnotationM ...

  5. java中如何通过Class获取类的属性、方法、注释

    public static String getPKName(Class clazz) { Field[] fields = clazz.getDeclaredFields(); for (Field ...

  6. 对Spring 容器管理事务支持的总结

    1.问题 Connection conn = DataSourceUtils.getConnection(); //开启事务 conn.setAutoCommit(false); try { Obje ...

  7. Android-DateUtil工具类

    时间相关工具类 public class DateUtil { private DateUtil(){} /** * 枚举日期格式 */ public enum DatePattern{ /** * ...

  8. Dapper 嵌套对象查询

    我有这样一个一对一关系的表结构:User->UserInfo User: /// <summary> /// 用户 /// </summary> [Serializabl ...

  9. EGOCache缓存框架详细讲解

    EGOCache是一个轻量级的缓存框架.用法简单方便,在现在的项目中,我就用到EGOCache来缓存下载过的照片和字符串. 有人可能会问到,缓存照片还需要用EGOCache吗?AFNetworking ...

  10. CentOS7布署.Net Core

    本文记录的所有东西,都是吸取别人的经验,自己实践得来,记录下来,也是为了某一天,用上的时候,能够更加的得心应手,平日的学习,都是未雨绸缪之举,但愿,这些笔记,也能帮上正在摸索的你. 第一步,下载虚拟机 ...