Skip to content

Commit e801b3b

Browse files
authored
Add github-git-cheat-sheet in zh_TW (#932)
* Add github-git-cheat-sheet in zh_TW * Update index.html for github-git-cheat-sheet in zh
1 parent da61d9b commit e801b3b

File tree

2 files changed

+176
-1
lines changed

2 files changed

+176
-1
lines changed
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
---
2+
layout: cheat-sheet
3+
redirect_to: false
4+
title: GitHub Git 速查清單
5+
byline: Git 是一個開源的分散式版本控制系統,可讓使用者在本機端(包含筆記型電腦與桌上型電腦)進行 GitHub 上的操作,這份速查清單羅列了使用者經常使用的指令,以提供使用者可快速參照。
6+
leadingpath: ../../../
7+
---
8+
9+
{% capture colOne %}
10+
## 安装 Git
11+
12+
### GitHub 桌面版
13+
[desktop.github.com](https://desktop.github.com)
14+
15+
### Git 通用平台版
16+
[git-scm.com](https://git-scm.com)
17+
18+
## Git 操作設定
19+
設定使用者在操作本機端 Git 的通用配置
20+
21+
```$ git config --global user.name "[name]"```
22+
23+
設定本機端 Git 使用者的名稱
24+
25+
```$ git config --global user.email "[email address]"```
26+
27+
設定本機端 Git 使用者的電子郵件
28+
29+
```$ git config --global color.ui auto```
30+
31+
啟用本機端使用命令列時的彩色輸出,提高使用 Git 的可讀性
32+
33+
## 分支
34+
35+
分支在使用者操作 Git 時扮演重要的角色。使用者提出的任何提交 (commit) 都會當前所在的分支上。使用 `git status` 可查看當前所在的分支。
36+
37+
```$ git branch [branch-name]```
38+
39+
建立一個新的分支
40+
41+
```$ git switch -c [branch-name]```
42+
43+
切換到指定分支,使用者的工作目錄會基於該分支更新
44+
45+
```$ git merge [branch]```
46+
47+
將指定分支的檔案歷程合併到當前分支。相同的結果經常會透過合併請求(Pull Request)達成,但此指令仍在本機端扮演重要的角色。
48+
49+
```$ git branch -d [branch-name]```
50+
51+
删除指定分支
52+
53+
{% endcapture %}
54+
<div class="col-md-6">
55+
{{ colOne | markdownify }}
56+
</div>
57+
58+
59+
{% capture colTwo %}
60+
61+
## 建立 Git 倉儲
62+
63+
使用者可透過兩種途徑來建立一個 Git 倉儲,第一,在本機端建立後,再推送到 GitHub;第二,取得該 Git 倉儲連結後,複製 (clone) 一份到本機端。
64+
65+
```$ git init```
66+
67+
使用者可透過 `git init` 指令,在本機端建立一個作為 Git 倉儲的資料夾目錄,並可透過以下指令建立本地倉儲與 GitHub 倉儲的連結。
68+
69+
```$ git remote add origin [url]```
70+
71+
指定一個 URL 為 `[url]` 的遠端倉儲 `origin` 作為本地倉儲的連結點。
72+
73+
```$ git clone [url]```
74+
75+
複製 (clone) 一個存在 GitHub 上的倉儲到本機端,其中包含所有檔案、分支與提交(commits)
76+
77+
## .gitignore 文件
78+
79+
使用者在一些情形下不希望 Git 追蹤部分檔案的狀態,這個時候可透過名為 `.gitignore` 的檔案達成,使用者可以在 [github.com/github/gitignore](https://github.com/github/gitignore) 找到有參考價值的 `.gitignore` 範本。
80+
81+
## 同步更改
82+
83+
將本地端的 Git 倉儲與遠端的 GitHub 倉儲進行狀態同步
84+
85+
```$ git fetch```
86+
87+
下載遠端分支的所有歷史
88+
89+
```$ git merge```
90+
91+
將遠端分支合併到當前本地端的分支
92+
93+
```$ git push```
94+
95+
將當前本地端的分支上傳到 GitHub
96+
97+
```$ git pull```
98+
99+
讀取 GitHub 遠端分支的對應提交,來更新使用者本地端當前的分支。當使用者接連著下達 `git fetch``git merge` 的指令,效果等同於直接下達 `git pull` 指令。
100+
101+
{% endcapture %}
102+
<div class="col-md-6">
103+
{{ colTwo | markdownify }}
104+
</div>
105+
<div class="clearfix"></div>
106+
107+
{% capture colThree %}
108+
109+
## 管理 Git 追蹤狀態變更
110+
111+
檢視專案檔案的變更歷史
112+
113+
```$ git log```
114+
115+
列出當前分支的變更歷史
116+
117+
```$ git log --follow [file]```
118+
119+
列出指定檔案的變更歷史,包括重新命名
120+
121+
```$ git diff [first-branch]...[second-branch]```
122+
123+
顯示兩個分支的差異處
124+
125+
```$ git show [commit]```
126+
127+
顯示指定提交的詮釋資料與內容變化
128+
129+
```$ git add [file]```
130+
131+
對文件進行快照,以讓 Git 納入版本控制
132+
133+
```$ git commit -m "[descriptive message]"```
134+
135+
將快照正式納入 Git 的版本控制歷史
136+
137+
## 修復提交
138+
139+
清除錯誤提交並修正
140+
141+
```$ git reset [commit]```
142+
143+
撤銷所有 `[commit]` 後的提交,並在本地端先保留該撤銷內容
144+
145+
```$ git reset --hard [commit]```
146+
147+
撤銷並抹除所有 `[commit]` 後的提交
148+
149+
> 特別注意!修改版本控制紀錄可能造成不好的後果。如果你需要修改遠端 GitHub 既有的提交,請小心操作。如果你需要幫助,可在社群 [github.community](https://github.community) 提出,或連繫 GitHub 窗口。
150+
151+
{% endcapture %}
152+
<div class="col-md-6">
153+
{{ colThree | markdownify }}
154+
</div>
155+
156+
{% capture colFour %}
157+
158+
## 術語清單
159+
160+
- **git**: 一個開源的分散式版本控制系統
161+
- **GitHub**: 一個讓使用者在使用本地端 Git 時,可進行遠端託管和協作管理的平台
162+
- **commit**: 提交,在 Git 的架構中作為一個物件,存放著當前倉儲狀態的快照,並以 SHA 形式存在
163+
- **branch**: 分支,通常用於區分 commit 的用途與專案的目標
164+
- **clone**: 複製,透過 `clone` 可讓使用者複製遠端倉儲到本地端,並進行後續的一系列操作
165+
- **remote**: 遠端,一個可被專案成員或大眾所觸及的遠端倉儲,有權限的使用者將會提交他們的檔案變更到此倉儲
166+
- **fork**: 副本,使用者可建立一個被其他使用者所擁有之遠端倉儲副本
167+
- **pull request**: 合併請求,當使用者變更倉儲內容後,需要透過合併請求,尋求倉儲所有人的同意,方能成為該倉儲的正式內容;透過合併請求,可讓提交人、倉儲關係人進行討論與測試
168+
- **HEAD**: 表示使用者當前的工作目錄。使用者可透過 `git checkout` 切換到不同的分支、標記 (tags) 或提交,`HEAD` 也會因此改變
169+
170+
{% endcapture %}
171+
<div class="col-md-6">
172+
{{ colFour | markdownify }}
173+
</div>
174+
<div class="clearfix"></div>

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ <h2 class="mt-2">Using Git</h2>
5151
<li><a class="d-flex flex-items-center" href="{{ site.baseurl }}/downloads/sk/github-git-cheat-sheet/"><span class="d-flex mr-2">{% octicon download %}</span> Slovenský</a></li>
5252
<li><a class="d-flex flex-items-center" href="{{ site.baseurl }}/downloads/tr/github-git-cheat-sheet/"><span class="d-flex mr-2">{% octicon download %}</span> Türkçe</a></li>
5353
<li><a class="d-flex flex-items-center" href="{{ site.baseurl }}/downloads/ua/github-git-cheat-sheet/"><span class="d-flex mr-2">{% octicon download %}</span> Ukrainian</a></li>
54-
<li><a class="d-flex flex-items-center" href="{{ site.baseurl }}/downloads/zh_CN/github-git-cheat-sheet/"><span class="d-flex mr-2">{% octicon download %}</span> 中文</a></li>
54+
<li><a class="d-flex flex-items-center" href="{{ site.baseurl }}/downloads/zh_CN/github-git-cheat-sheet/"><span class="d-flex mr-2">{% octicon download %}</span> 簡體中文</a></li>
55+
<li><a class="d-flex flex-items-center" href="{{ site.baseurl }}/downloads/zh_TW/github-git-cheat-sheet/"><span class="d-flex mr-2">{% octicon download %}</span> 繁體中文</a></li>
5556
</ul>
5657
</div>
5758

0 commit comments

Comments
 (0)