简体   繁体   English

git 的替代方案是什么 --shallow-since 使用 git 克隆深度

[英]What's the alternative to git --shallow-since using git clone depth

The git server I am cloning does not support shallow-since.我克隆的git服务器不支持shallow-since。 When I try to do so, I get the following error:当我尝试这样做时,出现以下错误:

fatal: Server does not support --shallow-since

I don't mind using git clone -depth=N instead, but how can I determine the N for my commit?我不介意改用git clone -depth=N ,但是如何确定提交的 N 呢?

Technically, these are different:从技术上讲,这些是不同的:

  • --shallow-since= date obtains commits whose commit-timestamp is later than (and perhaps equal to, boundaries are hard ) the given timestamp; --shallow-since= date获取提交时间戳晚于(并且可能等于,boundaries are hard)给定时间戳的提交;
  • --depth= number obtains commits whose counting-depth from names (branch names, tag names, and any other names you tell Git to use) is within the given number of steps. --depth= number获取其名称(分支名称、标记名称和您告诉 Git 使用的任何其他名称)的计数深度在给定步数内的提交。

That is, consider a Git repository with the following commits:也就是说,考虑具有以下提交的 Git 存储库:

A--B--C   <-- master
    \
     D--E--F--G   <-- develop

Suppose that the dates for C , E , F , and G are all this year, and A , B , and D are all the previous year.假设CEFG都是今年的日期, ABD都是前一年的日期。 If you do:如果你这样做:

git clone --shallow-since=<this year> --no-single-branch

you'll get commits C and EFG like this:你会得到这样的提交CEFG

...--C   <-- origin/master

...--E--F--G  <-- origin/develop

However, if you do:但是,如果您这样做:

git clone --depth=2 --no-single-branch you will get:

...--B--C   <-- origin/master

...--F--G   <-- origin/develop

ie, two commits from each name.即,每个名称的两次提交。 (There's no linkage from G back to B as that requires going four steps back from G to reach D , and we told Git to cut things off after two steps.) (没有从G回到B的链接,因为这需要从G向后退四步才能到达D ,我们告诉 Git 在两步后切断一切。)

Since --depth enables --single-branch by default, this peculiarity tends to get hidden: if you're only telling your clone to make an origin/master , it does not matter if the same depth would have applied to each other name too.由于--depth默认启用--single-branch ,这种特性往往会被隐藏:如果你只是告诉你的克隆制作一个origin/master ,那么相同的深度是否适用于彼此的名字并不重要也。 Adding the --no-single-branch option makes the difference much clearer.添加--no-single-branch选项使差异更加清晰。

In any case, if you don't have direct access to the server, the obvious way to calculate the depth is to make a full (but optionally, single-branch) clone, then examine the committer dates in the repository you now have locally.在任何情况下,如果您不能直接访问服务器,计算深度的明显方法是进行完整(但可选,单分支)克隆,然后检查您现在在本地拥有的存储库中的提交者日期. You can then count the revisions from the last date you want to the branch tip, which tells you how many commits to clone.然后你可以计算从你想要的最后日期到分支提示的修订,它告诉你有多少提交要克隆。

Of course, by this time, you have a full clone, so you might as well just use it.当然,到这个时候,你已经有了一个完整的克隆,所以你也可以直接使用它。

A workable alternative is to make an initial clone with some fixed --depth .一个可行的替代方法是使用一些固定的--depth进行初始克隆。 Then, inspect the earliest commit's committer timestamp.然后,检查最早提交的提交者时间戳。 If that date is after your cutoff, use git fetch --deepen (or --depth again) to deepen the shallow clone.如果该日期在您的截止日期之后,请使用git fetch --deepen (或再次使用--depth )加深浅层克隆。 Repeat the inspect-and-deepen until the repository is deep enough.重复检查和加深直到存储库足够深。

(The number of commits to clone initially, then to add per fetch, depends on how long it takes to bring over each group of commits, vs the overhead involved in setting up another round of git fetch , so there's no obvious Right Number to use.) (最初要克隆的提交数,然后是每次提取添加的提交数,取决于将每组提交移交所需的时间,以及设置另一轮git fetch所涉及的开销,因此没有明显的正确数字可供使用.)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM