GIT - 稀疏结帐不按预期工作 [英] GIT - sparse checkout not working as expected

查看:171
本文介绍了GIT - 稀疏结帐不按预期工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上签出了一个git repo。
回购用于在根上拥有所有相关文件,但我必须进行一些更改,现在我有两个文件夹, src dist 并且我想跟踪两者。



我得到的问题是在我的服务器上,如果我拉,我现在必须在dist文件夹内导航以查看内容。



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

我遵循本教程:






另一种解决方案也可能适用于您:



将子文件夹拆分为新的分支/存储库 $ b $ pre $ #使用filter-branch将所需的文件夹提取到新的文件夹中分支
#完成工作后,您可以再次合并它。

git filter-branch --prune-empty --subdirectory-filter YOUR_FOLDER_NAME< branch>
#将主分支过滤到您的目录并删除空提交


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

这篇关于GIT - 稀疏结帐不按预期工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆