简体   繁体   中英

GIT - sparse checkout not working as expected

I've a git repo checked out on a server. 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.

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.

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:

  1. ssh into my server
  2. cd into the project folder
  3. git config core.sparsecheckout true
  4. echo dist/ >> .git/info/sparse-checkout
  5. git read-tree -mu HEAD

but nothing happend. I mean, i still need to navigate to myproject/dist to being able to see something.

I also tried to cat sparse-checkout file and dist/ is present. I tried git pull origin master as well, but with no luck.

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. 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.

 # 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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