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. python文件对比

    #-*- encoding:utf-8 -*- class loadDatas(object): def __init__(self): self.path='./data' def load_com ...

  2. (并查集)How Many Tables -- HDU --1213

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  3. cocos studio

    用了几天,和之前用的cocos creator以及unity的编辑器一对比,很多地方都挺反人类的哈... 拖拽和放大场景元素竟然还要切换一下编辑模式... 移动场景元素竟然没有单独控制x或者y方向的移 ...

  4. html.EditorForModel自定义模版

    https://www.cnblogs.com/lori/p/5969658.html  http://www.cnblogs.com/yinzixin/archive/2012/12/18/2821 ...

  5. string 和String的区别

    string 是 System.String 的别名,习惯上,我们把字符串当作对象时(有值的对象实体),我们用string.而我们把它当类时(需要字符串类中定义的方法),我们用String,比如: s ...

  6. log.debug(e.getMessage());

    private static final Log log = LogFactory.getLog(AbcAction.class); @ManagedProperty(name = "abc ...

  7. java 反射应用

    场景需求最近的一次解析数据包中,因为协议有改变,本来的定长的包,现在变为不定长的.举个例子,本来协议中规定,一个包中,有8个标签,但是每次上来的,不一定都有8个,没有的话,硬件过来的都是0.同时里面也 ...

  8. Dalsa线扫相机SDK下载和安装

    1.首先去官方网站下载SDK Support Downloads - Teledyne DALSA http://www.teledynedalsa.com/imaging/support/downl ...

  9. Java 类型转换工具类(持续更新)

    简介 将项目中用到的类型转换做个记录. 详细代码 @Component public class TypeUtil { // [start]字符串转各种格式 // 字符串转日期(格式:"yy ...

  10. 数据库如何从SQL server转换到SQLite

    我之前用的是SQL server数据库,但是客户那里觉得安装这个大的数据库比较卡,说是导致蓝屏了,硬往SQL server上赖,没有办法客户是上帝么,给他换个小点的数据库吧!考虑Access,不行这个 ...