User Tools

Site Tools


git_clone

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Last revision Both sides next revision
git_clone [2019/03/15 09:53]
rpjday [Shallow clones]
git_clone [2019/03/16 10:38]
rpjday [Shallow clones]
Line 54: Line 54:
 <​code>​ <​code>​
 $ git clone --depth 1 --single-branch <repo URL> $ git clone --depth 1 --single-branch <repo URL>
 +</​code>​
 +
 +From [[https://​marc.info/?​l=git&​m=155270782026511&​w=2|here]]:​
 +
 +<​code>​
 +Side note: there'​s also narrow/lazy clone (or something with the
 +promisor) but I still haven'​t caught up with that. So none of that
 +here, but I think we should eventually have some examples/​description.
 +
 +A shallow clone is basically a repository with commit history cut
 +short. If you have a commit though, you have full content. It's not
 +cut by paths or anything.
 +
 +"git clone --depth=X"​ the the normal way to do this. You get a
 +repository where all branches and tags have maximum X commits deep.
 +But since the main purpose of shallow clone is redude download,
 +--single-branch is made default when --depth is present, so you get
 +the default branch instead of all the branches (you would need
 +--no-single-branch for that). You could see these cut points with "git
 +log --decorate"​. I think they are marked "​crafted"​ or something.
 +
 +Once you have made a shallow clone, you could do everything like
 +usual. Local operations of course can only reach as far as the cut
 +points. Pull and push to a full clone are possible (it's even possible
 +to do so to another shallow clone).
 +
 +When you "git fetch",​ the cut points remain the same, so you get more
 +recent commits and the history depth increases. If you do "git fetch
 +--depth=X"​ then the cut points are adjusted so that you only have
 +maximum X commits deep for all select branches, the same way a shallow
 +clone is made initially. "git fetch --unshallow"​ can be used to turn a
 +shallow clone into a complete one. And I'm pretty sure you could turn
 +a complete one to shallow with "git fetch --depth"​.
 +
 +While --depth works fine most of the time, sometimes you want a
 +different way to define these shallow/cut points. --shallow-since and
 +--shallow-exclude are added as the result. --shallow-since cut the
 +history by a specific date (for all select branches).
 +--shallow-exclude cuts the history by a ref (often a tag). As I
 +mentioned before, it's mostly used to say "I want a shallow clone from
 +(but not including) v2.9.0"​.
 +
 +And I think that's pretty much it. There'​s --update-shallow option but
 +I can't remember when that's needed. Shallow clones may also prevent
 +you from using some optional features. Pack bitmap is one of those and
 +I think probably commit graph too. It's not technical limitation, just
 +lack of time/effort to support them in shallow clones.
 +-- 
 +Duy
 </​code>​ </​code>​
git_clone.txt ยท Last modified: 2019/03/16 10:40 by rpjday