|
| 1 | +# 关于 git 和 github |
| 2 | +## 常用词汇 |
| 3 | +- repo:代码仓库 |
| 4 | +- PR:即 pull request,合并请求 |
| 5 | +- branch:分支 |
| 6 | +- commit:提交记录 |
| 7 | +- merge:指 PR 合并到代码仓库的操作 |
| 8 | +- conflicts:合并冲突 |
| 9 | + |
| 10 | +## 开始之前 |
| 11 | +1. 首先,fork 一下 [challenges](https://github.com/FreeCodeCampChina/challenges/pulls) repo |
| 12 | +2. 把**你的 fork** 克隆到本地。注意,`your_name` 是你的 github ID: |
| 13 | +```bash |
| 14 | +git clone https://github.com/your_name/challenges.git |
| 15 | +``` |
| 16 | +3. 切换到 challenges 文件夹: |
| 17 | +```bash |
| 18 | +cd challenges |
| 19 | +``` |
| 20 | +4. 根据你在翻译的项目名称或者你正在做的事情,新建分支。注意,`your_branch_name` 是你的分支名,如 `translate-basic-html-and-html5`: |
| 21 | +```bash |
| 22 | +git checkout -b your_branch_name |
| 23 | +``` |
| 24 | +5. 在本地进行代码或文件修改 |
| 25 | +6. 修改完成后,先添加要提交的文件: |
| 26 | +```bash |
| 27 | +git add . # 添加全部有改动的文件 |
| 28 | + |
| 29 | +# 或者你也可以添加某一个文件 |
| 30 | +git add my.json # 添加 my.json 文件 |
| 31 | +``` |
| 32 | +7. 创建 commit。注意,请根据实际情况填写 commit message: |
| 33 | +```bash |
| 34 | +git commit -m "My commit message" |
| 35 | + |
| 36 | +# 或者你也可以打开你喜欢的编辑器(需要配置),在里面编写 commit message |
| 37 | +git commit |
| 38 | +``` |
| 39 | +8. 把本地更新推送到远程(即你的 fork): |
| 40 | +```bash |
| 41 | +git push origin your_branch_name |
| 42 | +``` |
| 43 | +9. 打开 github 页面,创建 PR |
| 44 | + |
| 45 | +## 同步远程更新至本地 |
| 46 | +1. 关联上游 repo 至本地项目。注意,`upstream` 只是一个本地的 reference,你可以根据自己的习惯命名: |
| 47 | +```bash |
| 48 | +git remote add upstream https://github.com/FreeCodeCampChina/challenges.git |
| 49 | +``` |
| 50 | +2. 获取上游更新,并应用到本地。以下提供三种方式: |
| 51 | + 1. 使用 pull 命令: |
| 52 | + ```bash |
| 53 | + git pull upstream translate |
| 54 | + ``` |
| 55 | + 2. 使用 rebase 命令: |
| 56 | + ```bash |
| 57 | + git fetch upstream |
| 58 | + git rebase upstream/translate |
| 59 | + ``` |
| 60 | + 3. 使用 pull 命令与 rebase flag(推荐): |
| 61 | + ```bash |
| 62 | + git pull --rebase upstream translate |
| 63 | + ``` |
| 64 | + |
| 65 | +## 注意 |
| 66 | +1. `pull` 或 `rebase` 之后,如果有 conflicts,可以先使用 `git status` 查看存在 conflicts 的文件。修改成需要的版本后: |
| 67 | + - 如果你使用了 `pull` 命令,你需要 `git add .` 然后 `git commit` |
| 68 | + - 如果你使用了 `rebase` 或 `pull --rebase` 命令,你需要 `git add .` 然后 `git rebase --continue` |
| 69 | +2. 解决冲突之后,需要更新至远程,否则只有你的本地有更新: |
| 70 | +```bash |
| 71 | +git push origin your_branch_name |
| 72 | +``` |
| 73 | +3. 如果出现错误提示(多出现于 `rebase` 和 `pull` 命令),请先使用 `git status` 命令检查本地是否有未解决完成的 conflicts |
| 74 | +4. 如果你已经用当前的 branch 开了 PR,那么更新这个 branch 至远程的同时,你的 PR 也会自动更新 |
| 75 | + |
| 76 | +## 一些原则 |
| 77 | +1. 建议使用 [git workflow](https://guides.github.com/introduction/flow/) 来进行分支的管理。这样我们可以提交 PR 之后继续在新的 branch 上进行后续的翻译。若需要更新当前的 PR,任何时候我们都可以切换回来 |
| 78 | +2. 不建议同时开两个相同类型(比如翻译)的 PR,请等待之前的 merge 之后再开新的 PR |
| 79 | +3. 更新(创建)PR 时,请更新 labels,方便管理 |
| 80 | + |
| 81 | +## 标签(labels) |
| 82 | +1. `ready for review`:新开 PR 的默认状态,请手动添加此标签 |
| 83 | +2. `need update`:已经 review 过的 PR,需要 PR 提交者按照评论做出修改 |
| 84 | +3. `comments addressed`:用来表示已经按照评论更新了的 PR,等待下一次 review |
| 85 | + |
0 commit comments