chromium 34 代码拉取及推送

01 创建工作目录

代码下载的工作目录,代码仓库将在该目录的src子目录中

mkdir d:\git\chromium && cd d:\git\chromium

这一步如果中途失败,并且产生了 d:\git\chromium\.gclient文件,
可以尝试如下命令更新

gclient sync --with_branch_heads --with_tags --output-json="log.json"

02 下载不带历史记录的最新版本main分支

不下载历史,只下载最新的 main 分支,这样下载下来的代码只有一条log记录。下载完成后,本地 .git 仓库 1.27GB

fetch --no-history chromium

下载完成后,生成

d:\git\chromium\src\.git
d:\git\chromium\src\*
d:\git\chromium\.gclient
d:\git\chromium\.gclient_entries

上面拉取的分支没有日志信息,git log -3 只有一条历史提交日志

03 不在在修改仓库配置前拉取代码

执行完 fetch --no-history chromium 后,不可以直接执行 git pull , git fetch , git fetch --all, git fetch --tag 这类的命令,因为默认的 .git\config 里面有两个所有的 分支和tag信息

	fetch = +refs/branch-heads/*:refs/remotes/branch-heads/*
	fetch = +refs/tags/*:refs/tags/*

会导致如下结果:
比如运行 git pull,那么就会在 .git\objects\pack\目录中生成一个临时文件,把所有的分支都下载下来,比如我这里下载到 80%时的结果。tmp_pack_ynqjCJ 临时文件 22GB多。
要把上面的两个fetch修改为自己想要的分支和tag。

git pull

第一次 git pull 时,要检查远程仓库对象个数,是比较慢的
实验观察下来,这个 git pull 的过程和拉取完整代码的时间几乎一致。虽然本地 .git 仓库增加很少。

  • 显示计算远程对象个数,比较慢
D:\git\chromium\src>git pull
remote: Counting objects: 7371722
  • 再是查找远程对象,也比较慢
D:\git\chromium\src>git pull
remote: Finding sources: 100% (16086128/16086128)
  • 最后是接收远程对象,这一步看似完全下载,实际上只有一少部分需要的内容才被下载。
D:\git\chromium\src>git pull
remote: Finding sources: 100% (16086128/16086128)
Receiving objects:  45% (7323535/16086128), 2.52 GiB | 1.78 MiB/s
Receiving objects:  59% (9544504/16086128), 3.20 GiB | 1.89 MiB/s
Receiving objects:  62% (9996249/16086128), 5.64 GiB | 2.29 MiB/s
Receiving objects:  62% (10094897/16086128), 6.38 GiB | 2.32 MiB/s
Receiving objects:  64% (10406789/16086128), 8.48 GiB | 2.20 MiB/s
Receiving objects:  65% (10464402/16086128), 8.90 GiB | 2.54 MiB/s
Receiving objects:  66% (10706509/16086128), 10.83 GiB | 2.31 MiB/s
Receiving objects:  70% (11269695/16086128), 14.37 GiB | 1.93 MiB/s
Receiving objects:  73% (11839004/16086128), 17.53 GiB | 2.25 MiB/s
Receiving objects:  75% (12106233/16086128), 18.81 GiB | 1.45 MiB/s
Receiving objects:  79% (12807410/16086128), 21.25 GiB | 1.99 MiB/s

fetch --no-history chromium 下载完成时,本地 .git 仓库是 1.27GB
git pull 到58%的时候是 .git1.33GB,命令行显示接收到 3.16GiB
git pull 到64%的时候是 .git1.33GB,命令行显示接收到 8.48GiB

04 拉取指定的tag标签

拉取指定tag(92.0.4515.109),(不带历史记录 --depth 1)

git fetch https://chromium.googlesource.com/chromium/src.git +refs/tags/92.0.4515.109 --depth 1

记得同时修改 .git\config 的配置信息

	#fetch = +refs/tags/*:refs/tags/*
	fetch = +refs/tags/92.0.4515.109:refs/tags/92.0.4515.109

05 拉取指定的分支

拉取指定分支(branch-heads/4515),(不带历史记录 --depth 1)

git fetch https://chromium.googlesource.com/chromium/src.git +refs/branch-heads/4515 --depth 1

记得同时修改 .git\config的配置信息

	#fetch = +refs/branch-heads/*:refs/remotes/branch-heads/*
	fetch = +refs/branch-heads/4515:refs/remotes/branch-heads/4515

git fetch 命令运行成功之后,都会改变 .git\FETCH_HEAD.git\packed-refs 文件的内容, 估计可以根据完整下载的对应内容手动修改这两个文件。

06 切换到目标分支

git checkout -b b4515 remotes/branch-heads/4515

07 同步代码

gclient sync --with_branch_heads --with_tags --output-json="log.json"

08 查看仓库大小

查看仓库大小:

git gc 
git count-objects -vH

09 推送代码到自己的gitlab仓库

需要又自己的gitlab账号,并且已经创建了 仓库,比如创建了名为 chromium 的仓库

注意 gitlab 的 master 分支是受保护的,默认无上传代码
要上传的分支一定要现在gitlab上面创建好。

所以要在github的服务端创建好有上传权限的分支。比如: b4515 分支。
注意:第一次上传 chrmoum 的指定分支的代码,最好是采用覆盖的方式。这样比较方便和干净。

注意:上传前需要设置一下仓库的pushurl
修改 .git\config文件中的 [remote "origin"] 中的内容,
如果没有添加pushurl,如果有,修改为和自己上传仓库目标一直的git地址。
注意 pull 和 pushurl 是可以不同的。

[remote "origin"]
	url = https://chromium.googlesource.com/chromium/src.git
	...
	pushurl = https://myself.gitlab.com/group01/chromium.git

把本地的 b4515 分支 上传到 gitlab 的 b4515 分支,采用覆盖方式上传。

注意: 一定要注意账号有push权限并且有覆盖的权限

# 进入本地 git 仓库目录
cd D:\git\chromium\src
# 切换到要上传的分支
git checkout b4515
git fetch
# 采用覆盖方式上传分支到远程 gitlab 仓库,注意gitlab上面一定已经创建了b4515的分支
git push -u -f origin b4515:b4515
# 或者 git push -u -f --no-thin origin b4515:b4515
# 注意 只有第一次上传或者确实要覆盖的时候,才带 -f 参数

可能出现的问题

A 一定要现在gitlab上面创建要上传的分支
B shallow update not allowed

如果原来下载代码时使用了 --depth 1,可能会出现 (shallow update not allowed) 类型错误。


# 出现 (shallow update not allowed) 错误,去掉克隆的提交的 grafted 标记
git filter-branch -- --all -f
或者
git filter-branch -f
C pre-receive hook declined

如果出现 (pre-receive hook declined) ,可能是因为没有正确设置分支对应关系或者没有运行git fetch 命令

git fetch
git branch --set-upstream-to=origin/b4515 b4515
git push --set-upstream origin b4515
D 如果切换 origin 内容

如果切换了remote 参考的url地址,要特别注意 B 项操作。
如果怀疑是因为切换remote 仓库地址因为的问题,可以重新操作。

git remote -v
# 删除原有origin或者更名
git remote rm origin

# 再次添加新的远程url
git remove add origin xxx
E 默认直接推送到自己仓库的代码完整吗?

一般来说,默认推送的代码是不完整的,因为很多子仓库是没有加入其中的。除非你手动把一些子仓库内容加入到自己的本地仓库后,在推送到自己的远程仓库。但这是不推荐的方式,这种方式会导致你后面升级很麻烦。

一般我们是很少修改子仓库的。

如果要修改了子仓库,最好子仓库独立上传,这样升级版本的时候,能方便些。

一般我们需要在自己的仓库中建立一个基线记录,然下按照这个基线 gclient sync 子仓库的代码。再 gclient runhoooks.之后,切换到自己的开发分支。

默认推送到本地gitlab的 仓库中的内容是没有 v8 之类的第三方仓库的。所以,从本地 gitlab 仓库 clone 代码后,还是需要切换到基线, gclient syncgclient runhooks 的。

F 关于 gclient 的 fetch 命令

gclient 中的fetch 可以下载大部分google系的代码。不仅仅是 chromium。
可以通过 fetch --help 来查看。

fetch --help
usage: fetch.py [options] <config> [--property=value [--property2=value2 ...]]

This script can be used to download the Chromium sources. See
http://www.chromium.org/developers/how-tos/get-the-code
for full usage instructions.

Valid options:
   -h, --help, help   Print this message.
   --nohooks          Don't run hooks after checkout.
   --force            (dangerous) Don't look for existing .gclient file.
   -n, --dry-run      Don't run commands, only print them.
   --no-history       Perform shallow clones, don't fetch the full git history.

Valid fetch configs:
  android
  android_internal
  breakpad
  chromium
  config_util
  crashpad
  dart
  depot_tools
  devtools-frontend
  flutter
  goma_client
  gyp
  infra
  infra_internal
  inspector_protocol
  ios
  ios_internal
  nacl
  naclports
  node-ci
  pdfium
  skia
  skia_buildbot
  syzygy
  v8
  webrtc
  webrtc_android
  webrtc_ios
  website

至少 v8, webrtc 都是可以用这个工具下载的。

10 参考

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值