5

We read about git narrow clones. Let's say we want to use this new feature in the extreme and just with minimal bandwidth edit one file from a massive remote repository and push back our commit.

The only examples one finds are git clone --no-checkout --filter=blob:none "file://$(pwd)/srv.bare" pc1 Let's add --depth 1 to save even more data traffic and disk space. But how do we specify that single remote file without triggering "does not appear to be a git repository" error? git version 2.17.0.290.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Dan Jacobson
  • 490
  • 3
  • 14
  • The [documentation](https://github.com/git/git/blob/fe0a9eaf31dd0c349ae4308498c33a5c3794b293/Documentation/rev-list-options.txt#L732) suggests `--filter=sparse:path=` as a rev-list option. I have not tried any of this stuff yet. – torek Apr 19 '18 at 00:02

1 Answers1

1

I have not tried it, but I think, after the cloning you should do:

$ cd <CLONE>
$ git config core.sparseCheckout true
$ echo dir/file >.git/info/sparse-checkout
$ git reset --hard

At the last command it will automatically fetch missing blob(s). Hopefully it will get only the needed ones.

As far as I understand it, the theory is that it fetches everything except blobs - the file contents. So, by checkout or any other operation, it should know exactly list of objects it is missing, and will request only those.

PS: the specifying file for a filter with --filter=sparse:path=<path>, as suggested in comments, could work locally, but in real-life case when server is at another computer it failed for me because server treats the argument as server file path, where it obviously did not exist.

PS2: if could be that you don't need depth. At checkout it is going to need only current blobs, not older ones. This did work for me with some early version of the feature. Though you still would have to fetch older trees. Actually, it also seems to fetch some blobs as well, but I did not play with it long enough.

Seth Robertson
  • 30,608
  • 7
  • 64
  • 57
max630
  • 8,762
  • 3
  • 30
  • 55
  • Now-a-days, there is is `git sparse-checkout set dir/file` command which replaces the `git config core.sparseCheckout true` and `echo dir/file >.git/info/sparse-checkout` to maintain better compatibility with potential future changes. – Seth Robertson Jul 27 '22 at 18:32