This is the second day of my participation in Gwen Challenge.
Git Clone is very slow and will fail. What would people do with that?
You might consider switching to a different download source, you might do something to speed up your Internet connection, but what if you’ve tried everything and it’s still slow?
I ran into this problem today when I needed to download typescript code from GitLab, but it was extremely slow:
git clone https://github.com/microsoft/TypeScript ts
Copy the code
After a long wait, I added a parameter:
git clone https://github.com/microsoft/TypeScript --depth=1 ts
Copy the code
This speed increased dozens of times, instant download finished.
Plus — Depth will only download a commit, so much less content and speed up.
The downloaded content can then be used to commit new commits and create new branches. It does not affect subsequent development, but it cannot switch to historical commit and historical branch.
I tested it with one of my projects. I first downloaded a commit:
Git add, commit, and push
Creating a new branch can also commit normally. The only downside is that you can’t switch to history commit and history branch.
This is useful in some scenarios: when you need to switch to a history branch, you can also calculate how many commits are required, and then specify a depth, which can also increase speed.
Have you ever wondered how this works?
Git principle
Git stores information through a number of objects:
- Glob objects store file contents
- Tree Object storage file path
- Commit The object stores the commit information and associates the tree
With a commit as the entry point, all associated trees and blobs are the contents of this commit.
Commits are related to each other, and head, branch, tag, and so on are Pointers to specific commits. This can be seen under.git/refs. This implements branching, tag, and other concepts based on commit.
Git is used to implement version management and branch switch functions through these three objects. All objects can be seen under.git/objects.
This is how Git works.
Blob, Tree, commit, head, Tag, branch, remote, etc.
You can download the rationale for a single COMMIT
Git associates all objects with a single commit, so if you don’t need history, you can download only one commit.
This still creates a new COMMIT based on that commit, associating a new blob, tree, etc. However, the historical commit, tree, and BLOb cannot be cut back because they have not been downloaded, nor can the corresponding tag, branch, and other Pointers. This is how we can download a single COMMIT and still create new branches, commits, etc.
conclusion
For large Git projects, you can add a –depth parameter to increase the speed significantly. The more historical commits you have, the faster the download will be.
You can create new Commits and branches and tags, but you can’t switch to historical commits, branches and tags.
We have sorted out the principle of Git: files and commit information are stored through tree, BLOb and COMMIT, and functions such as branches and tags are realized through the association between commit. Commit is the entry point, associating all trees and BLOBs.
We downloaded a commit that downloaded all the trees, bloBs, and refs (including tags, branches, etc.) associated with it. That’s how depth works.
Use this technique to improve git Clone speed for large projects without switching to historical commit and branch.