简体   繁体   English

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

[英]GIT - sparse checkout not working as expected

I've a git repo checked out on a server.我在服务器上检出了一个 git repo。 The repo used to have all the relevant files on the root, but i had to make some changes and now i have two folders, src and dist and i want to track both.该 repo 曾经在根目录上包含所有相关文件,但我必须进行一些更改,现在我有两个文件夹, srcdist ,我想跟踪这两个文件夹。

The problem i've got is that on my server, if i pull, i now have to navigate inside dist folder in order to see something.我遇到的问题是,在我的服务器上,如果我拉,我现在必须在 dist 文件夹中导航才能看到一些东西。

I tried to search a bit and i think that what i'd like to do is called sparse-checkout.我试着搜索了一下,我认为我想做的是所谓的稀疏结帐。

I followed this tutorial: http://jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/ , in particular the part that talks about an existing project and i did what mentioned:我遵循了本教程: http : //jasonkarns.com/blog/subdirectory-checkouts-with-git-sparse-checkout/ ,特别是谈论现有项目的部分,我做了提到的事情:

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

but nothing happend.但什么也没发生。 I mean, i still need to navigate to myproject/dist to being able to see something.我的意思是,我仍然需要导航到 myproject/dist 才能看到一些东西。

I also tried to cat sparse-checkout file and dist/ is present.我还尝试cat sparse-checkout文件并且dist/存在。 I tried git pull origin master as well, but with no luck.我也试过git pull origin master ,但没有运气。

Am i missing something here?我在这里错过了什么吗?

You did everything as it should be.你做了所有应该做的事情。


sparse checkout

With sparse checkout you basically tell Git to exclude a certain set of files from the working tree.通过稀疏结帐,您基本上可以告诉 Git 从工作树中排除某些文件集。 Those files will still be part of the repository but they won't show up in your working directory.这些文件仍将是存储库的一部分,但它们不会出现在您的工作目录中。

Internally, sparse checkout uses the skip-worktree flag to mark all the excluded files as always updated.在内部,稀疏检出使用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

在此处输入图片说明


Another solution which might work for you as well:另一种可能对您有用的解决方案:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM