3

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
Community
  • 1
  • 1
Kaah
  • 915
  • 3
  • 11
  • 26
  • What exactly do you want to do with `statics` once you've got its contents hoisted to the root? Is just getting the content of an arbitrary version enough (that's easy), or do you need to develop in it independently but still collaborate with the main project, or what? Describe the situation you're in and what needs doing without referring to features or abstractions of any vcs. – jthill May 23 '14 at 16:41
  • @jthill It just need to get content from an arbitrary version. It will NOT be developed independently. Do you have any idea how this can solved? – Kaah May 23 '14 at 19:32

2 Answers2

3

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.

jthill
  • 55,082
  • 5
  • 77
  • 137
0

I think it's impossible: sparse checkout mechanics is not a file relocation tool. As explained here when you employ sparse checkout, Git only operates on special bits set for entries in the index file. It does not relocate anything.

kostix
  • 51,517
  • 14
  • 93
  • 176
  • Thanks, this answer is good enough if not someone else has another idea of how this can be solved. – Kaah May 23 '14 at 19:31