代码之家  ›  专栏  ›  技术社区  ›  Alexander Mills

克隆git repo的子树/子目录

  •  1
  • Alexander Mills  · 技术社区  · 6 年前

    我在GitHub上有一个Git回购,看起来是这样的:

    .git/
    assets/
      tools/
        a.sh
        b.sh
        c.sh
    

    当然.git文件夹不在版本控制中,但是你知道了。我想将tools/*.sh复制到本地目录,路径如下:

    ./scripts/git/tools
    

    我当前的目录是一个git repo,它与远程git repo共享完全不同的历史记录,我只想从远程复制一些文件,不想合并任何内容。

    我想我可以这样做:

    git clone --path assets/tools/*.sh "$remote_repo"  ./scripts/git/tools
    

    但是这个命令不是真的,我可以用它来做这个吗?

    我唯一能想到的另一种方法是,将整个repo克隆到某个temp目录,然后复制文件,但这并没有那么有趣。