Skip to content

Commit

Permalink
doc(git): update docs/git.md (#931)
Browse files Browse the repository at this point in the history
  • Loading branch information
Qliangw authored Mar 6, 2025
1 parent 8ec4235 commit a0a9574
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,55 @@ Conventional Commmits
| `test:` | 添加测试代码或修正已有的测试 |
<!--rehype:className=left-align-->


patch 补丁的使用
----

### 简单创建

```bash
$ git diff commit_id > my.patch
```

### 简单应用

- **检查**补丁

```bash
# 检查下这个补丁能否被正常应用
$ git apply --check path/to/my.patch
```

- **使用**补丁

```
# 检查通过使用该补丁
$ git apply < path/to/my.patch
```

- 若有冲突则**解决**

```
# 检查不通过可以自动合入patch不冲突的代码,同时保留冲突部分
$ git apply --reject path/to/my.patch
```

<!--rehype:className=style-timeline-->

### Email patch 方式

```bash
# 创建指定 commit sha1 id 之前的 n 次提交补丁
$ git format-patch commit_id -n
# 创建 300f59991f22826c8478f0c019387c4ca815b085 这个提交的patch
$ git format-patch commit_id -1
# 提取当前分支最上面的3次提交,生成补丁
$ git format-patch -3
# 发送者可使用 git-send-email 发送 git format-patch 的结果给接收者
# 接收者保存邮件到文件 email.txt,然后应用补丁创建一个提交,会自动包含作者的信息
$ git am < email.txt
```

另见
---

Expand Down

0 comments on commit a0a9574

Please sign in to comment.