Reputation: 147
git clone --depth N ...
creates a shallow clone with history limited to the last N revisions and I can use git clone -b tag ...
to fetch the commits reachable from tag
. However, is there a way to fetch a repository (or a branch thereof) from a specific (tagged) commit up to the branch head?
Say, for example, I'd like to clone only the history starting from a specific release tag. So if the last few commits in the remote look like this
[master] ...
[master~1] ...
[master~2] ... <-- tag: x.x
[master~3] ...
...
Now I'd like to clone the history range x.x~1..
, without having to manually count the number of revisions to give to --depth
.
I guess the explanation given in the accepted answer to Why Isn't There A Git Clone Specific Commit Option? applies here as well, so there might not be a direct way.
Upvotes: 3
Views: 1357
Reputation: 29841
If running at least Git 2.11 on both client and server side, there's a work-around if you know the date of the tagged commit and which branch it is on:
git clone --branch <branch that contains tag> --shallow-since=<date of tagged commit> <url>
Upvotes: 1
Reputation: 488519
Indeed, there is no direct way, and this kind of counting or multiple-ref-based cloning would have to be implemented on the server side (the server delivering the initial shallow clone) for it to work within git's constraints.
There's an indirect way though: start with a depth 1 shallow clone, then deepen repeatedly until the tag appears. Annoyingly, git fetch --depth=<N>
won't pick up new tags (but you can use git ls-remote
or similar to get everything once on the shallow-clone client, and watch for the SHA-1). But I suspect this method would be so slow as to make it pretty worthless.
Upvotes: 1