【问题标题】:Checkout a Specific Folder within a Git Repository签出 Git 存储库中的特定文件夹
【发布时间】:2016-07-08 15:25:00
【问题描述】:

我在不同的存储库中有多个项目:

tools

thirdparty

shared
├──Common
├──Exceptions

multimedia
├──VolumeControl
├──VideoRenderer

android
├──Audio

例如android依赖shared/Common、shared/Exceptions、tools、thirdparty和多媒体/VolumeControl。

我试过了:

  1. 子模块:https://git-scm.com/book/en/v2/Git-Tools-Submodules
  2. 稀疏结帐:http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/

但是,它们都在 android 文件夹中检出或引入多媒体文件夹。相反,我希望它像:

android
├──Audio
├──VolumeControl (brought in from multimedia)

我该如何做到这一点?

注意:我曾经在 svn 中使用 lockexterns 来完成此操作。

【问题讨论】:

    标签: git git-submodules svn-externals git-sparse-checkout


    【解决方案1】:

    我想知道为什么 git-submodule 无法实现。我记得,使用子模块可以指定目标目录,因此您可能可以执行以下操作:

    $ cd Android
    $ git submodule add url/path-to-your-submodule-repo VolumeControl
    $ git diff --cached --submodule # OPTIONAL - To verify before commit
    $ git commit -m 'added multimedia/VolumeControl as sub-module'
    

    【讨论】:

      【解决方案2】:

      我该如何做到这一点?

      您可以使用git filter-branch 和或git subtree split

      filter-branch 将遍历每个提交,然后您可以只签出给定的文件,而 git subteree split 在您的情况下将是一个更好的选择。

      解释这两个选项,以便您选择您喜欢的选项。


      示例代码:

      filter-branch

      # Filter the master branch to your directory and remove empty commits
      git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME filter_from_branch
      

      这会将您想要的文件从给定文件夹检出到当前目录


      subtree split

      git subtree git-subtree - Merge 子树在一起或 split 存储库到子树中

      git subtree split -P <name-of-folder> -b <name-of-new-branch>
      

      【讨论】:

        猜你喜欢
        • 2015-02-24
        • 2018-12-07
        • 1970-01-01
        • 2010-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多