Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git sparse checkout without leading directories

I understand how to configure a sparse checkout in Git, but I was wondering if it's possible to eliminate the leading directories. For example, say I have a Git repository with a folder structure like so:

  • folder1/foo
  • folder2/foo/bar/stuff
  • folder3/another/foo/bar/stuff2

And I only want the contents inside stuff2. For sparse checkout of those directories, the .git/info/spare-checkout file would look like this:

folder3/another/foo/bar/stuff2/

My problem is after I'm finished with the sparse checkout, I don't see stuff2 or the contents of stuff2 inside the root of my directory; I see folder3 and then all of the subdirectories leading up to stuff2.

I'm guessing the answer to this question is that it's not possible with Git, but I just wanted to make sure. This is one (and only) behavior of SVN that I miss; the ability to run svn co https://url.com/myrepo/folder3/another/foo/bar/stuff2 . and have the contents dumped into the current directory.

like image 216
Scott Crooks Avatar asked Jan 20 '26 04:01

Scott Crooks


1 Answers

Some tools like git hub have the ability to view a given folder directly. However to operate on only one folder at a time is forbidden in git as the whole repository must be present to perform the hash of the new commit and make the diff for the commit

It is also discussed here How to git-pull all but one folder

like image 129
Mike Forsberg Avatar answered Jan 21 '26 21:01

Mike Forsberg