Google gclient 命令行参数及选项

在 GFW 面前,你需要知道的关于 Google gclient 的命令行参数及选项。

先看帮助信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
$ gclient --help
Usage: gclient.py <command> [options]

Meta checkout dependency manager for Git.

Commands are:
config creates a .gclient file in the current directory
fetch fetches upstream commits for all modules
runhooks runs hooks for files that have been modified in the local working copy
sync checkout/update all modules
......

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-j JOBS, --jobs=JOBS Specify how many SCM commands can run in parallel;
defaults to {X} on this machine

$ gclient sync --help
Usage: gclient.py sync [options]

Checkout/update all modules.

Options:
--version show program's version number and exit
-h, --help show this help message and exit
-j JOBS, --jobs=JOBS Specify how many SCM commands can run in parallel;
defaults to {X} on this machine
-f, --force force update even for unchanged modules
......

关键命令及参数:

  • -j,指定并发任务数,默认是 CPU 核数
    • 如果 CPU 核数较多,且网络使用了代理,代理程序可能不支持如此高的并发量,此时网络可能出问题
    • 可以将其设置为较小的值,比如 4 或者 8
  • gclient sync -f,强制重新下载所依赖的模块(仅针对不存在的模块)
    • 如果子模块下载除了问题,你一气之下删除了子模块对应的文件夹,那么 gclient sync 后续会自动忽略
    • 使用 -f/--force 参数,可以重新下载/生成依赖模块的文件夹
  • gclient fetch,更新所有子模块(如果上游有新的 commits 的话)

总之,在 GFW 面前会存在各种奇怪的问题,多使用以下命令基本能解决:

1
2
3
gclient sync -f
gclient fetch
git reset --hard