Total Pageviews

Saturday, 11 June 2022

'--depth 1'的作用

 在运行git clone命令时,在git clone命令的末尾加上 --depth 1可以加快克隆的速度从而成功克隆,否则在克隆很多内容时,克隆可能会失败。 

------

https://github.com/bower/bower/issues/217#issuecomment-12759766说:

This should work nicely:

git clone URL -b TAG --depth 1 

https://github.com/bower/bower/issues/217#issuecomment-13944036说:

As mentioned above, you can replace the code that currently does a clone followed by a checkout of the correct branch with the single git clone URL -b TAG --depth 1 mentioned above.

Alternatively, when you do a git clone --depth 1 without specifying the tag you might get all of the objects needed for a particular tag, in which case you just git checkout TAG. But then again, you might not, so you actually have to do a git fetch TAG first to make sure.

So, currently if a repo is cloned it is added to the cache, then a copy is made in the components folder where a git checkout TAG is done. Then if you need it again you can go to the cached version. So I would recommend the following logic:

  1. If the repo we want is not cached, do a git clone --depth 1 -b TAG into the cache.
  2. If the repo in the cache does not contain the tag we need, do a git fetch TAG
  3. Copy the repo from the cache and git checkout TAG

If it is decided that caching isn't so important any more then you can just clone straight into the components folder. From some testing and reading around it seems that --depth 1 doesn't really affect download sizes by all that much so you probably still want caching.

 


No comments:

Post a Comment