【问题标题】:GIT - sparse checkout not working as expectedGIT - 稀疏结帐未按预期工作
【发布时间】:2016-06-18 18:40:22
【问题描述】:

我在服务器上签出了一个 git repo。 repo 曾经在根目录下拥有所有相关文件,但我必须进行一些更改,现在我有两个文件夹,srcdist,我想同时跟踪这两个文件夹。

我遇到的问题是,在我的服务器上,如果我拉,我现在必须在 dist 文件夹中导航才能看到一些东西。

我尝试搜索了一下,我认为我想做的就是所谓的稀疏结帐。

我遵循了这个教程:http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/,尤其是关于现有项目的部分,我做了提到的事情:

  1. ssh 进入我的服务器
  2. cd 进入项目文件夹
  3. git config core.sparsecheckout true
  4. echo dist/ >> .git/info/sparse-checkout
  5. git read-tree -mu HEAD

但什么也没发生。我的意思是,我仍然需要导航到 myproject/dist 才能看到一些东西。

我还尝试了cat sparse-checkout 文件并且dist/ 存在。 我也试过git pull origin master,但没有成功。

我错过了什么吗?

【问题讨论】:

    标签: git github


    【解决方案1】:

    你做了所有应该做的事。


    sparse checkout

    通过稀疏检出,您基本上可以告诉 Git 从工作树中排除特定的文件集。 这些文件仍将是存储库的一部分,但它们不会显示在您的工作目录中。

    在内部,稀疏检出使用 skip-worktree 标志将所有排除的文件标记为始终更新。

    # enable sparse checkout in an existing repository:
    git config core.sparseCheckout true
    
    # Create a .git/info/sparse-checkout file containing the
    # paths to include/exclude from your working directory. 
    
    # Update your working directory with 
    git read-tree -mu HEAD
    


    另一种可能也适合您的解决方案:

    Splitting a subfolder out into a new branch/repository

    # use filter-branch to extract only the desired folder into a new branch
    # once you done with your work you can always merge it back again.
    
    git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME <branch>
    # Filter the master branch to your directory and remove empty commits
    

    【讨论】:

    • 这很方便,但是如何在不产生冲突的情况下再次从原点拉取? (例如,当我只想要过滤时,我将如何做一个 git pull 而不是从原点下拉所有内容)
    猜你喜欢
    • 2020-09-10
    • 2020-11-23
    • 2012-11-04
    • 2012-03-23
    • 1970-01-01
    • 2019-11-19
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    相关资源
    最近更新 更多