获取远程分支上的git sha深度 [英] Get git sha depth on a remote branch

查看:163
本文介绍了获取远程分支上的git sha深度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 git clone --depth [N] ,但要使用 N 来保证我得到了一个特定的sha。



我如何确定远程回购中某个sha的深度。请注意克隆它在本地做到这一点是捕获22.我想这样做,以避免克隆它。

解决方案

选项1:

如果您有能力获取存储库的完整克隆,则可以使用 git rev-list HEAD ^ 42c6ee9 --count



这会找到任何特定提交的深度。没有远程版本,所以这只有在您可以保留一个完整副本,然后 ssh 来计算深度时才有效。



这允许您只需克隆一次,但是您可以在以下所有时间回答问题,以便进行浅拷贝。



使用 git clone --depth 1 那么迭代 git fetch --depth = i + 1 实际上是一个值得测试的好主意。 (也由上面的@leon提出)。

根据仓库的特点,这是有道理的。



EG Django存储库有23330个提交(在测试时)



./ full.sh - 提取完整的本地存储库

  git clone https://github.com/django/django 

./ oracle.sh - 如果你神奇地知道正确的答案。下载时间。

  git clone --depth 10 https://github.com/django/django.git 

./ search.sh - 迭代

  git clone --depth 1 https://github.com/django/django.git 
cd django

i = 1
直到git show 5d35181> / dev / null

i = $((i + 1))
git fetch --depth = $ i
完成

搜索虽然有开销,但仍可能会比完整的克隆快。

  ./ full.sh 21.34s 
./oracle.sh 1.12s
./search.sh 3.05s


I would like to use git clone --depth [N] , but to use such N that guarantees that a particular sha is obtained.

How I can determine the depth of a sha of in a remote repo. Note cloning it locally to do that is catch 22. I would like to do that to avoid cloning it all.

解决方案

Option 1:

If you have the ability to get to a full clone of the repository, you can find the depth using git rev-list HEAD ^42c6ee9 --count.

This will find the depth of any particular commit. There is no remote version so this only works if you can maintain a full copy and then ssh into it to figure out the depth.

This allows you to only have to clone once but then you'll be able to answer the question for all the following times you'd like to do a shallow copy.

Option 2:

Using git clone --depth 1 then iterating on git fetch --depth=i+1 is actually a good idea worth testing. (Also proposed by @leon above).

Depending on the characteristics of your repository, this will make sense.

E.g. Django repository has 23330 commits (at the time of testing)

./full.sh - pulling the full local repository

git clone https://github.com/django/django

./oracle.sh - if you magically knew the right answer. lower bound on time.

git clone --depth 10 https://github.com/django/django.git

./search.sh - iterating

git clone --depth 1 https://github.com/django/django.git
cd django

i=1
until git show 5d35181 > /dev/null
do
    i=$((i+1))
    git fetch --depth=$i
done

The search, while there is overhead, may still come out faster then a full clone.

./full.sh  21.34s
./oracle.sh 1.12s
./search.sh 3.05s

这篇关于获取远程分支上的git sha深度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆