我怎样才能克隆一个Git仓库的子文件夹,并使子文件夹中的所有文件都在根目录下? [英] How can I clone only a subfolder of a Git repository and make all the files in the subfolder end up in the root?

查看:162
本文介绍了我怎样才能克隆一个Git仓库的子文件夹,并使子文件夹中的所有文件都在根目录下?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我意识到类似的问题已经被问到:我如何克隆仅Git存储库的子目录?然而,我无法找到我的具体问题的答案,所以请不要将其标记为重复。



我有一个叫做statics /的子文件夹。我希望该子文件夹的文件最终位于本地回购的根目录中。



我做了 echo statics />> .git / info / sparse-checkout 但我在我的本地仓库中以 /statics/file.css 结尾,当我执行pull时。我只想 /file.css



我该如何做?

使用的命令参考:

  git init 
git remote add -f https:/ /github.com/xxx/xxx.git
git config core.sparsecheckout true
echo statics />> .git / info / sparse-checkout
git pull origin master


解决方案 div>

这是任意树的 git checkout 。有一个分公司叫你 scratchpad ,你可能偶尔想记录其后代的内容。

  git checkout scratchpad 
git read-tree -um --ggressive`git write-tree`:anycommityoulike:statics

,任何时候都会覆盖工作树内容,而您只是不在乎,请将 -um 更改为 - 然后做一个 git checkout -f



edit:just do the结帐,而我们已经在那里。


I realize that similar questions has been asked before: How do I clone a subdirectory only of a Git repository? However I couldnt find the answer to my specific question so please do not mark it as duplicate.

I have a subfolder called statics/ in my repo. I want the files of that subfolder end up in the root of my local repo.

I did echo statics/ >> .git/info/sparse-checkout but I end of with /statics/file.css in my local repo when I do a pull. I just want /file.css.

How do I do this?

Reference of commands used:

git init
git remote add -f https://github.com/xxx/xxx.git
git config core.sparsecheckout true
echo statics/ >> .git/info/sparse-checkout
git pull origin master

解决方案

Here's git checkout for an arbitrary tree. Have a branch you call scratchpad whose content you might occasionally want to record for posterity.

git checkout scratchpad
git read-tree -um --aggressive `git write-tree`: anycommityoulike:statics

and any time that balks at overwriting worktree content and you just don't care, change -um to -u and do a git checkout -f afterwards.

edit: just do the checkout while we're already there.

这篇关于我怎样才能克隆一个Git仓库的子文件夹,并使子文件夹中的所有文件都在根目录下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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