为了账号安全,请及时绑定邮箱和手机立即绑定

更新 git repo 所需的最少网络流量是多少?

更新 git repo 所需的最少网络流量是多少?

蝴蝶刀刀 2022-06-28 17:34:23
git很慢,让我们自动化上下文是我想编写一个更新约 150 个 git 存储库的脚本。与我们之前的 subversion 安装相比,Gitlab/hub 在网络上的速度几乎慢了一个数量级,例如:(dev) go|c:\srv\lib\examradar> python -c "import time;start=time.time();import os;os.system('svn up');print time.time() - start"Updating '.':At revision 31294.0.559000015259(dev) go|c:\srv\lib\code\dkrepo> python -c "import time;start=time.time();import os;os.system('git pull');print time.time() - start"Already up to date.Current branch master is up to date.4.31999993324IE。150 个 svn 存储库至少需要 84 秒,而 150 个 git 存储库将需要 10 分钟以上(!)(在 win10 上的 wsl 上的 ubuntu 中运行相同的命令会产生 0.48 秒和 1.52 秒——看图 ;-)使用脚本,我们可以并行执行所有“简单”更新,并将 git-case 缩短到约 100 秒。不幸的是,我们遇到了超时(经常这样做git rev-parse @{u}),所以我正在寻找最有效的方法来更新 git repo 并善待 git 服务器。我对“作弊”持开放态度,例如,如果在 git 之外有办法知道(很有可能)不需要更新 repo(webhooks?,后台 fetch-daemons?)搞砸回购是非常具有破坏性的,所以如果拉动会产生合并冲突,它应该保释。当前代码我正在使用 python 调用包来简化调用命令。我也会对只使用原始 git 命令的答案感到满意。这是我到目前为止...首先是一个便捷函数,它打印正在运行的命令及其输出,并将输出作为字符串返回:from invoke import taskdef runner(c):    return lambda cmd: c.run(cmd, hide=False, echo=True).stdout.strip()然后是获取回购状态的任务/功能。我相信只有git fetch和 git rev-parse @{u}` 接触网络(?):@taskdef get_status(c, wc):    """Return a set containing the strings          local-clean     if there are no local changes          local-dirty     if there are local changes          untracked       if there are files that haven't been added to git          remote-change   if upstream has changed          local-change    if there are local committed (but not pushed) changes          diverged        if local and upstream have diverged    """    run = runner(c)    with c.cd(wc):        status = []        porcelain = run('git status --porcelain')        if porcelain == "":            status.append('local-clean')        else:            status.append('local-dirty')        untracked = run('git ls-files --others --exclude-standard')        if untracked:            status.append('untracked')        run('git fetch')    # only interested in current branch so not using `git remote update`
查看完整描述

1 回答

?
一只甜甜圈

TA贡献1836条经验 获得超5个赞

您不必要求 git 同步完整的存储库历史记录,它通常是最方便且便宜的,可以在您在那里的时候完成。在比较它们之前尝试让 svn 和 git 做同样的事情。 svn up只关心当前的提示,对其余的根本不做任何检查。


$ time git ls-remote git://github.com/torvalds/linux refs/heads/master

6e8ba0098e241a5425f7aa6d950a5a00c44c9781        refs/heads/master


real    0m0.536s

user    0m0.004s

sys     0m0.007s

$

毫不奇怪,使用 svn 和 git 检查单个远程提示所花费的时间大致相同。


您当前分支的简称是git symbolic-ref -q --short HEAD(否则您不在分支上)。


所以你的 svn up 正在做的更接近的等价物是


if branch=`git symbolic-ref -q --short HEAD` && 

    remote=`git config branch.$branch.remote` &&

    merge=`git config branch.$branch.merge` &&

    upstreamtip=`git ls-remote $remote $merge | cut -f1` &&

    test $upstreamtip != `git rev-parse @{u}`

        then git pull $remote $merge

fi


查看完整回答
反对 回复 2022-06-28
  • 1 回答
  • 0 关注
  • 135 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号