GIT - 稀疏结账未按预期工作

Nic*_*ick 2 git github

我在服务器上签出了一个 git 存储库。该存储库过去在根目录下包含所有相关文件,但我必须进行一些更改,现在我有两个文件夹,src并且dist我想跟踪这两个文件夹。

我遇到的问题是,在我的服务器上,如果我拉动,我现在必须在 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 读取树-mu HEAD

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

我也尝试cat sparse-checkout提交并dist/在场。我git pull origin master也尝试过,但没有运气。

我在这里错过了什么吗?

Cod*_*ard 5

你做了一切应该做的事。


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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


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

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
Run Code Online (Sandbox Code Playgroud)