git - 我需要从 Bitbucket Git 存储库中 check out 单个文件夹

标签 git bitbucket

<分区>

我有一个包含大约 20 个文件夹的存储库,这些文件夹是在我从 SVN 转换到 Git 时创建的。是否可以从 Git 存储库(在 Bitbucket 上) check out 单个文件夹?或者我是否必须将这些文件夹中的每一个都设为单独的存储库?

最佳答案

编辑 稀疏 checkout 基本上可以这样但更好(请参阅相关问题)。只是,我的回答注意做一个克隆以及,因为只做稀疏 checkout 。

您可以通过两个(粗略的)步骤破解它:

  1. check out 一个浅拷贝

    cd /tmp
    git clone --depth=1 --bare git@myhosted_repo/project.git
    
    (cd project.git && git branch master)
    
  2. 现在 - 设置您的工作树(单独)

    mkdir /tmp/workdir
    cd /tmp/workdir
    git init .
    
    # add the shallow clone as a remote
    git remote add --fetch shallow /tmp/project.git
    
  3. 真正的技巧:

    # read a subtree from the remote, shallow branch
    git read-tree --prefix somedir -u shallow/master:testcases/
    

    (假设你的 repo 有一个名为 testcases 的目录)

您最终会得到一个工作目录,该目录仅包含来自 testcases/ 的文件,位于名为 somedir 的子目录中

结果:

  • 它只从托管仓库中获得一个修订版。好(商标)
  • 它只会从该修订版中 check out 单个子文件夹。好(商标)
  • 这是神秘的。如果你打算将 somedir 放在其他一些 repo 中,它会特别糟糕(可以完成子树 merge ,但我不会在那里烧手指)

关于git - 我需要从 Bitbucket Git 存储库中 check out 单个文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20724127/

相关文章:

git - 什么是内容级 merge ?

git - aix 7.1 上的 bitbucket ssh 克隆失败

Git 推送失败。错误 : RPC failed; result=56, HTTP 代码 = 0

node.js - 从 .env 文件创建 kubernetes env var secret

version-control - 如何从提交日志中将问题标记为已解决?

macos - GIT 无法 pull : failed to symlink 'path/filename' : File name too long

git - 我应该排除 .gitignore 中的 Aurelia 脚本文件夹吗?

git - lntelliJ IDEA EAP 12 和 Bitbucket(Git 或 Mercurial)

Git 日志 : filter by commit's author date

git 跟踪不同名称的分支