Skip to content

Commit a5fbf24

Browse files
📝 Refactor navigation items in docusaurus.config.js and enhance Git documentation
- Simplified navbar configuration by removing commented-out sections and directly adding links for "开发" and "书架". - Expanded Git documentation with additional explanations on `git pull`, `git fetch`, and merging strategies. - Clarified the differences between various Git commands and their implications in collaborative environments. - Improved overall structure and readability of the Git documentation, ensuring better understanding for users.
1 parent ba2dcd6 commit a5fbf24

File tree

2 files changed

+51
-36
lines changed

2 files changed

+51
-36
lines changed

docs/docs/编程外的基础/Git.md

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ flowchart LR
2929
D -- git pull --> A
3030
```
3131

32+
在git中,有许多操作可以实现同样的效果,例如拉取远程分支
33+
34+
- `git pull` 获取远程变化并自动合并到当前分支,默认不清理不再存在的远程跟踪分支。
35+
- `git fetch origin --prune` 获取远程变化并清理不再存在的远程跟踪分支,但不合并到当前分支。
36+
37+
因此在AI编程的今天,如果我们的不了解git原理就使用提示词获取git命令,可能会出现意料之外的情况。git命令的全部难点都在于,如何处理与合并分支。
38+
3239
[Interactive Git Courses](https://ooloo.io/project/github-flow/mindset)了解如何在 GitHub (一个托管和协作管理 Git 仓库的平台)团队中使用 Git
3340

34-
## 常用操作
41+
## 基础操作
3542

3643
**初始化一个新的 Git 仓库:**
3744

@@ -55,11 +62,8 @@ git status
5562

5663
```bash showLineNumbers
5764
git add <file_name>
58-
```
59-
60-
**添加所有改动到暂存区:**
6165

62-
```bash showLineNumbers
66+
# 添加所有改动到暂存区
6367
git add .
6468
```
6569

@@ -78,37 +82,36 @@ git log
7882
**拉取远程仓库的改动并合并到当前分支:**
7983

8084
```bash showLineNumbers
81-
git pull
82-
```
83-
84-
**将改动推送到远程仓库:**
85+
# 对于个人的仓库,可以直接使用 git pull
86+
git pull # 实际上是 git fetch 和 git merge 的组合
8587

86-
```bash showLineNumbers
87-
git push
88-
```
88+
# 对于多人协作的项目,可以按如下流程
89+
git fetch # 只拉取
90+
git diff origin/main..main
8991

90-
**创建新的分支:**
92+
# 查看本地与远程的差异
93+
# 在 Git 中,A..B 两点语法表示"在 B 中但不在 A 中的提交
9194

92-
```bash showLineNumbers
93-
git branch <branch_name>
94-
```
95+
git fetch origin
9596

96-
**切换到特定的分支:**
97+
# 约定俗成:当你克隆一个仓库时,Git 会自动将你克隆的远程仓库命名为 "origin"
98+
# 可自定义:这个名称完全可以更改,不是强制的,可以是任何名称
9799

98-
```bash showLineNumbers
99-
git checkout <branch_name>
100+
git merge origin/feature-branch # 合并远程仓库的feature-branch分支
101+
git fetch --prune # 获取更新并移除已删除的远程分支引用
100102
```
101103

102-
**合并特定分支到当前分支**
104+
**设置用户名和邮箱用于推送分支(一次配置,长期有效)**
103105

104106
```bash showLineNumbers
105-
git merge <branch_name>
107+
git config --global user.name "您的姓名"
108+
git config --global user.email "您的邮箱@example.com"
106109
```
107110

108-
**查看当前分支和远程分支**
111+
**将改动推送到远程仓库**
109112

110113
```bash showLineNumbers
111-
git branch -a
114+
git push
112115
```
113116

114117
## 分支
@@ -127,6 +130,8 @@ git branch newBranch # 创建本地分支
127130
git checkout newBranch # 切换到本地分支
128131

129132
git checkout -b newBranch # 创建并切换到分支
133+
134+
git merge <branch_name> # 将指定的 branch_name 合并到当前分支
130135
```
131136

132137
## 版本
@@ -170,9 +175,9 @@ git branch -a --contains Tag_V1.0.0 # 看看哪个分支包含这个tag/commit
170175

171176
Git commit的规范是为了更好的管理代码,方便后续的代码维护和版本回退。
172177

173-
因此它并不是一个硬性要求,但是在团队协作中,规范的commit message可以让团队更好的理解代码的变更。
178+
因此它并不是一个硬性要求,但是在团队协作中,规范的commit message可以让团队更好的理解代码的变更。现在AI编辑器也可以自动生成格式优雅,内容准确的commit信息。
174179

175-
个人开发者可以根据自己的习惯来定义规范,譬如:Gitmoji
180+
个人开发者也可以根据自己的习惯来定义规范,譬如:Gitmoji
176181

177182
> Gitmoji是一种在Git提交消息中使用表情符号来表示提交目的的规范。每个表情符号(emoji)都代表着一种特定的提交类型,使提交消息更加生动和易读。Gitmoji 的目标是通过简单的图标和表情符号传达清晰的信息,从而提高代码提交历史的可读性和可理解性。
178183

docusaurus.config.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,29 @@ module.exports = {
188188
navbar: {
189189
hideOnScroll: false,
190190
items: [
191+
// {
192+
// position: "left",
193+
// label: "文档",
194+
// items: [
195+
// {
196+
// label: "开发",
197+
// to: "/docs",
198+
// },
199+
// {
200+
// label: "书架",
201+
// to: "/read",
202+
// },
203+
// ],
204+
// },
191205
{
206+
to: "/docs",
192207
position: "left",
193-
label: "文档",
194-
items: [
195-
{
196-
label: "开发",
197-
to: "/docs",
198-
},
199-
{
200-
label: "书架",
201-
to: "/read",
202-
},
203-
],
208+
label: "开发",
209+
},
210+
{
211+
to: "/read",
212+
position: "left",
213+
label: "书架",
204214
},
205215
{
206216
to: "/blog/archive",

0 commit comments

Comments
 (0)