V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
luckypoem
V2EX  ›  Linux

怎么克隆非 branch 的源码?

  •  
  •   luckypoem · 2016-08-13 15:17:35 +08:00 · 2964 次点击
    这是一个创建于 2814 天前的主题,其中的信息可能已经有所发展或是发生改变。
    hi.请教各位一个问题,这个地址 https://github.com/agbell/agbell.github.io/tree/hakyll 的内容怎么克隆下来?我只能成功运行 git clone https://github.com/agbell/agbell.github.io
    运行 git clone https://github.com/agbell/agbell.github.io/tree/hakyll 失败。
    11 条回复    2016-08-15 09:28:37 +08:00
    owt5008137
        1
    owt5008137  
       2016-08-13 15:25:12 +08:00 via Android
    luckypoem
        2
    luckypoem  
    OP
       2016-08-13 15:30:04 +08:00
    @owt5008137 ,谢谢你
    snnn
        3
    snnn  
       2016-08-13 17:18:22 +08:00
    BTW ,不管你怎么 clone, 下载下来的都是所有 branch 。
    luckypoem
        4
    luckypoem  
    OP
       2016-08-13 18:03:09 +08:00
    标题写错了。应是:怎么克隆非 master 的源码?
    Hanxv
        5
    Hanxv  
       2016-08-13 19:58:25 +08:00 via Android
    你本地切换分支啊
    fatedier
        6
    fatedier  
       2016-08-13 20:09:08 +08:00
    先把项目直接 clone 下来,之后切换到那个分支, git checkout -b hakyll origin:hakyll
    smallpath
        7
    smallpath  
       2016-08-13 20:18:22 +08:00
    懒癌的话, 可以先 clone master 分支, 再在本地新建想要拉取的分支, 最后 pull 新建的分支
    shimanooo
        8
    shimanooo  
       2016-08-13 20:25:21 +08:00
    clone 之后,远程分支在本地会变成 origin/xxx 这样。
    然后 git 自动建立 master 分支,跟踪 origin/master 。
    zhaoace
        9
    zhaoace  
       2016-08-14 14:07:21 +08:00
    我来帮忙解释一下发生了什么吧。

    https://github.com/agbell/agbell.github.io/tree/hakyll 这个 link 里面
    1.「 https://github.com/agbell/agbell.github.io 」这个部分是 repo 的实际地址
    2. tree 代表是是个 folder ,如果是实际代码一般是 blob 表示是二进制文件。 比如 「 https://github.com/agbell/agbell.github.io/blob/master/about.html
    3. hakyll 是这个库的分支。

    所以你直接 clone 整个完整 url 是不行的。


    @owt5008137 是帮你 clone 了这个 repo 然后切换到了对应分支。
    「 git clone -b hakyll https://github.com/agbell/agbell.github.io

    你也可以分两步走:
    1. clone 整个库: git clone https://github.com/agbell/agbell.github.io
    2. 切换到对应分支 git check out hakyll


    另外如果你只想要代码,不想在 git 上花时间的话你可以 直接 download , 这样就直接 download 该 url 对应的分支的代码啦。
    adoyle
        10
    adoyle  
       2016-08-15 09:10:33 +08:00
    git clone 有 --single-branch 选项。可以不用下载所有分支。
    ilotuo
        11
    ilotuo  
       2016-08-15 09:28:37 +08:00 via Android
    git checkout origin/xxxx
    git checkout myxxx
    git commit
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2707 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 15:27 · PVG 23:27 · LAX 08:27 · JFK 11:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.