Skip to content

与官网保持同步 [Maintainers] (Keep updated with the official site)

Alex Li edited this page Nov 16, 2023 · 20 revisions

与官网保持同步 (Maintainers)

上游 https://github.com/flutter/website

准备工作

  • Fork 本仓库。
  • 如果已经 Fork 过,请先在 https://github.com/{{你的用户名}}/flutter.cn 点击「Fetch upstream」-> 「Fetch and merge」同步上游仓库。直到提示 This branch is even with cfug:main. 为止(见下图)。
  • git clone 自己的 Fork。
Before After
Sync with upstream Synced

获得代码

# 拉取仓库
git clone https://github.com/你的用户名/flutter.cn --recursive
# 进入项目文件夹
cd flutter.cn
# 切换到其他分支,切勿在主分支操作
git switch -c sync/20231116
# 添加远程同步仓库
git remote add cfug https://github.com/cfug/flutter.cn.git
git remote add flutter https://github.com/flutter/website.git
# 拉取 CFUG 仓库,一般不会有冲突,同步之后直接 push
git pull cfug main
git push
# 拉取官方文档仓库,这个时候可能会出现一些冲突和更新等
git pull flutter main 

# 初始化 submodule (每次更新都需要执行)
git submodule update --init --recursive
# 同步最新 submodule 至本地仓库
git submodule update --remote

如果与官方文档有更新冲突,则可能类似如下输出:

WX20190709-124531@2x

文档处理

这里是目前 maintainers 总结的相对推荐的做法,未来也会有更方便简洁的方法。

处理更新的文档(git conflict: both modified)

为了保持文档的更新,我们需要合并文档中的更新。

查看冲突文件列表

建议可以使用 git status 命令来查看 conflict 的内容,打开相关的文件进行冲突处理:

image

处理冲突内容

冲突类型 1)原始文档格式修改:

image


冲突类型 2)原始文档有更新:

image


冲突类型 3)因为文档新增而造成的元数据更新:

image


其他类型 / 举例:

image

如果一篇文档更新的地方较多,可以到 flutter/website 复制最新的文档,用译者翻译的中文进行逐行填充。 (左边是上游最新文档,中间是编辑器,右边是译者翻译的内容)

处理新增的文档 (git: new file)

等待本次文档同步结束(merged)之后,需要对新增的文档进行处理, 需要发布新任务(发一个新的 Issue,增补协作文档等),同时要完成标题的翻译。

发布新任务

打开 Issues 区,仿照之前通过 Issue 发布的任务,需要预计完成时间等,最后通过 Issue 发布新任务。

#### 增补协作文档 协作文档 里,展开 H、I、J 列,增补 D - K 列的内容。

Git 处理

与上游 submodule 同步

# 同步最新 submodule 至本地仓库,命令需要手动 Ctrl+C 结束
git submodule foreach "(git pull)&"
# 添加所有的 submodule 更改
git add examples/codelabs
git add flutter
git add site-shared
# 提交本次 sync
git commit
# 推送到 Github
git push

然后向本 repo 发起 pull request。

submodule 问题处理

出现这样的问题的时候

git add .
error: 'examples/codelabs' does not have a commit checked out
fatal: updating files failed

查看 submodule 的仓库

[submodule "site-shared"]
    path = site-shared
    url = https://github.com/dart-lang/site-shared
    branch = main
[submodule "flutter"]
    path = flutter
    url = https://github.com/flutter/flutter
    branch = stable
[submodule "examples/codelabs"]
    path = examples/codelabs
    url = https://github.com/flutter/codelabs

然后

git clone https://github.com/dart-lang/site-shared site-shared
git clone -b stable https://github.com/flutter/flutter flutter
git clone https://github.com/flutter/codelabs examples/codelabs

执行 git add . 即可。

CI 测试报错

=> ERROR: some code excerpts were not refreshed!

在根目录下执行:

make setup # 配置环境
# export PATH=/workspaces/flutter.cn/flutter/bin/:$PATH
# 这里你还可能需要为当前 terminal 配置 PATH 环境变量,确保代码中的 Dart 命令可以正常执行
./tool/refresh-code-excerpts.sh # 执行代码刷新

这个 CI 主要是保证每一份 .md 文档里的示例代码都与官方源保持一致。

image

后续工作

完成代码同步后,新建 PR 并 ref 到 https://github.com/cfug/flutter.cn/issues/374 即可。