Home > OS >  How to clone only a specified range of commits, omitting both newer and older ones to save bandwidth
How to clone only a specified range of commits, omitting both newer and older ones to save bandwidth

Time:01-01

Task:

To do git bisect on a repo say https://example.git , with both the ends of the bisecting range being quite older: say: za3bca (newer) and fabce1 (older).

Being on limited bandwidth, I don't want to download all the commits up to the latest end of the range as I know for sure I don't need them.

My approach:

So, as given on this git documentation page for git clone, I want to use both the options: --depth <depth> and --shallow-since=<date> together.

  • I will specify the date of the older end of the range, e.g. 20220212 (yyyymmdd),
  • I've counted the number of commits in between the range (to say 100), and will supply some more than that as the "depth"
git clone https://example.git --shallow-since=20220212 --depth 100

But doing this gives the error: fatal: error processing shallow info: 4

CodePudding user response:

Two things: first, your --shallow-since datespec doesn't parse correctly. Try 2022-02-12 instead.

But that still won't do what you want, because --depth and --shallow-since both specify how far back to go from the ref that's being checked out (the remote's primary branch HEAD, if not specified). You can't use --depth to specify how far forward to go from the commit that --shallow-since finds.

If there's a tag or a branch head at or near the end of your bisect range, you could use that as the ref to check out with the --branch option (despite the name, it accepts both branches and tags):

git clone --single-branch --shallow-since=2022-02-12 --branch=end-point https://some.repo

If there isn't, then I don't think there's much you can do, other than convince someone to make such a tag or branch for you :)

CodePudding user response:

The most direct way is tag the tips you're starting from on the server side and fetch those with --shallow-since. Many servers these days are configured to let you fetch arbitrary reachable (and some, even unreachable) commits, specifically to cater to this kind of bit-scrimping impulse, so if it's annoying to tag them you can try looking them up and specifying the start commit explicitly:

git fetch origin --shallow-since=2022212 \
         602c0cb92c50a259c29138d8e107615569c0767d:refs/tags/starthere
  •  Tags:  
  • git
  • Related