Skip to content

Commit 0163763

Browse files
committed
feat: 添加入门清单
1 parent d84fff5 commit 0163763

File tree

4 files changed

+249
-2
lines changed

4 files changed

+249
-2
lines changed

cheatsheet.md

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
<!--idoc:ignore:start-->
2+
入门备忘清单
3+
===
4+
<!--idoc:ignore:end-->
5+
6+
![git 入门备忘清单](./git.png)
7+
<!--rehype:style= max-width: 660px; margin: 0 auto;-->
8+
9+
## 创建存储库
10+
11+
```bash
12+
# 创建一个新的本地存储库
13+
$ git init [项目名称]
14+
15+
# 克隆存储库
16+
$ git clone <git仓库url地址>
17+
18+
# 将存储库克隆到指定目录
19+
$ git clone <git仓库url地址> <我的文件夹>
20+
```
21+
22+
## 配置
23+
24+
```bash
25+
# 设置将附加到您的提交(commit)和标签(tags)的名称
26+
$ git config --global user.name "name"
27+
28+
# 设置将附加到您的提交(commit)和标签(tags)的电子邮件地址
29+
$ git config --global user.email "email"
30+
31+
# 启用 Git 输出的一些着色
32+
$ git config --global color.ui auto
33+
34+
# 在文本编辑器中编辑全局配置文件
35+
$ git config --global --edit
36+
```
37+
38+
## 变更
39+
40+
```bash
41+
# 在工作目录中显示修改后的文件,为您的下一次提交暂存
42+
$ git status
43+
44+
# 暂存文件,准备提交
45+
$ git add [file]
46+
47+
# 暂存所有更改的文件,准备提交
48+
$ git add .
49+
50+
# 将所有暂存文件提交到版本化历史记录
51+
$ git commit -m "commit message"
52+
53+
# 将所有跟踪的文件提交到版本化历史记录
54+
$ git commit -am "commit message"
55+
56+
# 取消暂存文件,保留文件更改
57+
$ git reset [file]
58+
59+
# 将所有内容恢复到最后一次提交
60+
$ git reset --hard
61+
62+
# 已更改但未暂存(staged)的内容的差异
63+
$ git diff
64+
65+
# 已暂存(staged)但尚未提交的内容的差异
66+
$ git diff --staged
67+
68+
# 在指定之前应用当前分支的任何提交
69+
$ git rebase [branch]
70+
```
71+
72+
## 分支
73+
74+
```bash
75+
# 列出所有本地分支
76+
$ git branch
77+
78+
# 列出所有分支,本地和远程
79+
$ git branch -av
80+
81+
# 切换到 my_branch,并更新工作目录
82+
$ git checkout my_branch
83+
84+
# 创建一个名为 new_branch 的新分支
85+
$ git checkout -b new_branch
86+
87+
# 删除名为 my_branch 的分支
88+
$ git branch -d my_branch
89+
90+
# 将 branchA 分支合并到 branchB 分之上
91+
$ git checkout branchB
92+
$ git merge branchA
93+
94+
# 标记当前提交
95+
$ git tag my_tag
96+
97+
# 重命名为 new_name
98+
$ git branch -m <new_name>
99+
100+
# 推送和重置
101+
$ git push origin -u <new_name>
102+
103+
# 删除远程分支
104+
$ git push origin --delete <old>
105+
```
106+
107+
## 观察存储库
108+
109+
```bash
110+
# 显示当前活动分支的提交历史
111+
$ git log
112+
113+
# 显示 branchA 上不在 branchB 上的提交
114+
$ git log branchB..branchA
115+
116+
# 显示更改文件的提交,即使重命名
117+
$ git log --follow [file]
118+
119+
# 显示 branchA 中的内容与 branchB 中的差异
120+
$ git diff branchB...branchA
121+
122+
# 在 Git 中以 人类可读 格式显示任何对象
123+
$ git show [SHA]
124+
125+
# 按内容搜索更改
126+
$ git log -S'<a term in the source>'
127+
128+
# 显示特定文件随时间的变化
129+
$ git log -p <file_name>
130+
131+
# 打印出很酷的日志可视化
132+
$ git log --pretty=oneline --graph --decorate --all
133+
```
134+
135+
## 同步
136+
137+
```bash
138+
# 从该 Git 远程获取所有分支
139+
$ git fetch [alias]
140+
141+
# 将远程分支合并到当前分支以使其保持最新状态
142+
$ git merge [alias]/[branch]
143+
No fast-forward
144+
$ git merge --no-ff [alias]/[branch]
145+
Only fast-forward
146+
$ git merge --ff-only [alias]/[branch]
147+
148+
# 将本地分支提交传输到远程存储库分支
149+
$ git push [alias] [branch]
150+
151+
# 从跟踪远程分支获取并合并任何提交
152+
$ git pull
153+
154+
# 将另一个分支的一个特定提交合并到当前分支
155+
$ git cherry-pick [commit_id]
156+
```
157+
158+
## 远程
159+
160+
```bash
161+
# 添加一个 git URL 作为别名(alias)
162+
$ git remote add [alias] [url]
163+
164+
# 显示您设置的远程存储库的名称
165+
$ git remote
166+
167+
# 显示远程存储库的名称和 URL
168+
$ git remote -v
169+
170+
# 删除远程存储库
171+
$ git remote rm [remote repo name]
172+
173+
# 更改 git repo 的 URL
174+
$ git remote set-url origin [git_url]
175+
```
176+
177+
## 临时提交
178+
179+
```bash
180+
# 保存已修改和分阶段的更改
181+
$ git stash
182+
183+
# 列出隐藏文件更改的堆栈顺序
184+
$ git stash list
185+
186+
# 从存储堆栈顶部编写工作
187+
$ git stash pop
188+
189+
# 丢弃存储堆栈顶部的更改
190+
$ git stash drop
191+
```
192+
193+
## 跟踪路径更改
194+
195+
```bash
196+
# 从项目中删除文件并暂存删除以进行提交
197+
$ git rm [file]
198+
199+
# 更改现有文件路径并暂存移动
200+
$ git mv [existing-path] [new-path]
201+
202+
# 显示所有提交日志,并指示任何移动的路径
203+
$ git log --stat -M
204+
```
205+
206+
## 忽略文件
207+
208+
`.gitignore` 文件指定了 Git 应该忽略的故意未跟踪的文件
209+
210+
```bash
211+
/logs/*
212+
213+
# "!" 意思是不要忽视
214+
!logs/.gitkeep
215+
216+
# 忽略 Mac 系统文件
217+
.DS_store
218+
219+
# 忽略 node_modules 文件夹
220+
node_modules
221+
222+
# 忽略 SASS 配置文件
223+
.sass-cache
224+
```
225+
226+
## 分支
227+
228+
```bash
229+
# 列出所有分支及其上游
230+
$ git branch -vv
231+
232+
# 快速切换到上一个分支
233+
$ git checkout -
234+
235+
# 只获取远程分支
236+
$ git branch -r
237+
238+
# 从另一个分支签出单个文件
239+
$ git checkout <branch> -- <file>
240+
```

git.png

72 KB
Loading

idoc.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,11 @@ editButton:
99

1010
footer: |
1111
Released under the MIT License. Copyright © 2022 Kenny Wong<br />
12-
Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>
12+
Generated by <a href="https://github.com/jaywcjlove/idoc" target="_blank">idoc</a>
13+
14+
sideEffectFiles:
15+
- cheatsheet.md
16+
17+
menus:
18+
首页: index.html
19+
入门清单: cheatsheet.html

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
"url": "https://github.com/jaywcjlove/git-tips.git"
1111
},
1212
"dependencies": {
13-
"idoc": "^1.10.5"
13+
"idoc": "^1.21.1"
1414
}
1515
}

0 commit comments

Comments
 (0)