Git sparse checkout without leading directories [d

2020-06-17 05:15发布

问题:

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.

回答1:

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