-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit.html
More file actions
354 lines (296 loc) · 9.76 KB
/
Copy pathgit.html
File metadata and controls
354 lines (296 loc) · 9.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Git Commands Table of Contents</title>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
line-height: 1.6;
background-color: #1e1e1e;
/* Dark background color */
color: #c9d1d9;
/* Light text color */
margin: 0;
padding: 20px;
}
h1,
h2 {
text-align: center;
color: #58a6ff;
/* Light blue heading color */
}
pre {
background-color: #2d2d2d;
/* Darker code block background color */
padding: 10px;
border-radius: 6px;
overflow-x: auto;
max-width: 720px; /* 設定表格的最大寬度 */
margin: 0 auto; /* 將程式碼塊水平置中 */
}
code {
background-color: #2d2d2d;
/* Dark code block background color */
padding: 2px 5px;
border-radius: 4px;
font-family: Consolas, "Courier New", monospace;
color: #e6e6e6;
/* White code text color */
}
.comment {
color: #727275 !important;
/* Less prominent color for comments */
}
a {
color: #58a6ff;
/* Light blue link color */
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h2 {
margin-top: 20px;
color: #c9d1d9;
/* Light text color for subheadings */
}
table {
border-collapse: collapse;
max-width: 720px; /* 設定表格的最大寬度 */
margin: 0 auto;
/* 將表格水平置中 */
}
th,
td {
border: 1px solid #282828;
padding: 8px;
}
th {
text-align: center;
}
td a {
color: #f8f8f8;
}
</style>
</head>
<body>
<h1>Git Commands Table of Contents</h1>
<!-- Jump Links -->
<table>
<thead>
<tr>
<th></th>
<th>選項</th>
<th>中文描述</th>
<th>具體內容</th>
</tr>
</thead>
<tbody>
<tr>
<td>1.</td>
<td><a href="#section-1">將 Respository 加入 git</a></td>
<td>加入版本控制</td>
<td>將檔案加入版本控制系統,以便追蹤檔案的變更。</td>
</tr>
<tr>
<td>2.</td>
<td><a href="#section-2">git clone</a></td>
<td>克隆版本庫</td>
<td>從遠端伺服器複製一份版本庫到本地端。</td>
</tr>
<tr>
<td>3.</td>
<td><a href="#section-3">git branch</a></td>
<td>分支管理</td>
<td>建立、切換、合併分支。</td>
</tr>
<tr>
<td>4.</td>
<td><a href="#section-4">git tag</a></td>
<td>加上標籤</td>
<td>標記版本庫的特定狀態。</td>
</tr>
<tr>
<td>5.</td>
<td><a href="#section-5">git commit 相關</a></td>
<td>提交變更</td>
<td>將本地端的變更提交到版本庫。</td>
</tr>
<tr>
<td>6.</td>
<td><a href="#section-6">git merge</a></td>
<td>合併分支</td>
<td>將兩個或多個分支合併在一起。</td>
</tr>
<tr>
<td>7.</td>
<td><a href="#section-7">git stash</a></td>
<td>暫存變更</td>
<td>暫時儲存本地端的變更,以便稍後恢復。</td>
</tr>
<tr>
<td>8.</td>
<td><a href="#section-8">git diff</a></td>
<td>查看差異</td>
<td>查看兩個版本之間的差異。</td>
</tr>
<tr>
<td>9.</td>
<td><a href="#section-9">git ignore 相關</a></td>
<td>忽略檔案</td>
<td>忽略特定檔案的變更,以免追蹤。</td>
</tr>
<tr>
<td>10.</td>
<td><a href="#section-10">git rebase 相關</a></td>
<td>設定配置</td>
<td>設定 Git 的使用者設定。</td>
</tr>
</tbody>
</table>
<h2 id="section-1">1. 將 Respository 加入 git</h2>
<pre><code>
$ git init
$ git add .
$ git commit -m "[commit message]"
$ git remote add origin [github repository url]
<span class="comment"># remove remote</span>
<span class="comment"># git remote remove origin</span>
<span class="comment"># 第一次 push</span>
$ git push --setupstream origin [branch name]
<span class="comment"># 以後 push</span>
$ git push
</code></pre>
<h2 id="section-2">2. git clone</h2>
<pre><code>
<span class="comment"># clone 別人的 repo 後 push 到自己的 new repo</span>
$ git clone [someone's github repository url]
$ git remote rename origin upstream
$ git remote add origin [new repository url]
$ git push origin master
</code></pre>
<h2 id="section-3">3. git branch</h2>
<pre><code>
<span class="comment"># 新增 branch</span>
$ git branch [branch name]
<span class="comment"># 如果有 [branch name] 就切換過去,沒有的話就建立該 branch 並切換到該 branch</span>
$ git checkout -b [branch name]
<span class="comment"># 將 branch apple 重新命名為 banana</span>
$ git branch -m apple banana
<span class="comment"># 刪除 local 的 branch</span>
$ git branch -d [branch name]
<span class="comment"># 強制刪除 local 的 branch</span>
$ git branch -D [branch name]
<span class="comment"># 刪除 remote 的 branch</span>
$ git push origin --delete [remote branch name]
<span class="comment"># 查看 local 的 branch</span>
$ git branch -v
<span class="comment"># 查看 remote 的 branch</span>
$ git branch -rv
<span class="comment"># 同時查看 local 和 remote 的 branch</span>
$ git branch -av
<span class="comment"># 在 feature branch 開出 sub branch</span>
$ git checkout -b sub feature
<span class="comment"># 或是</span>
$ git branch sub feature
<span class="comment"># 新增 local branch 並連結 remote repository 的 branch</span>
$ git checkout --track origin/[remote branch name]
<span class="comment"># 等同於</span>
$ git checkout -b [remote branch name]
$ git branch --set-upstream-to=origin/[remote branch name] [remote branch name]
<span class="comment"># 新增 local branch 並 push 到 remote 上</span>
$ git checkout -b [branch name]
$ git push -u origin [branch name]
</code></pre>
<h2 id="section-4">4. git tag</h2>
<pre><code>
<span class="comment"># 在 local 端新增 tag</span>
$ git tag [tag_name]
<span class="comment"># push local 的 tag 到 remote</span>
$ git push origin [tag_name]
<span class="comment"># 刪除 local 端 tag</span>
$ git tag -d [tag_name]
<span class="comment"># 刪除 remote 端 tag</span>
$ git push --delete origin [tag_name]
</code></pre>
<h2 id="section-5">5. commit 相關</h2>
<pre><code>
<span class="comment"># 捨棄最後一次的 commit</span>
$ git revert HEAD --no-edit
<span class="comment"># 捨棄最近一次的 commit</span>
$ git reset master^
<span class="comment"># 捨棄目前 branch 上最近一次的 commit</span>
$ git reset HEAD~1
<span class="comment"># 恢復到某次 commit 的狀態,同時更新 remote 狀態</span>
$ git reset SHA1 --hard
<span class="comment"># 強制 push,忽略 remote 版本較新的問題</span>
$ git push -f
<span class="comment"># 捨棄某次的 commit</span>
$ git revert SHA1
<span class="comment"># 修改 commit message - 尚未 push 到遠端</span>
$ git commit --amend -m "New message"
<span class="comment"># 修改 commit message - 已經 push 到遠端,修改目前最新的 commit message</span>
$ git commit --amend -m "New message"
$ git push --force origin <branchName>
<span class="comment"># cherry-pick</span>
$ git cherry-pick <commit-hash>
</code></pre>
<h2 id="section-6">6. git merge</h2>
<pre><code>
<span class="comment"># merge branchA 到 branchB</span>
$ git checkout branchB
$ git merge branchA
</code></pre>
<h2 id="section-7">7. git stash</h2>
<pre><code>
<span class="comment"># 暫存修改過的檔案</span>
$ git stash
<span class="comment"># 暫存修改過的檔案(包含 untrack 的檔案)</span>
$ git stash -u
<span class="comment"># 查看目前有哪些暫存</span>
$ git stash list
<span class="comment"># 把最新一次的暫存拿出來用</span>
$ git stash pop
</code></pre>
<h2 id="section-8">8. git diff</h2>
<pre><code>
<span class="comment"># 比較目前檔案和上一個 commit 作的更動(如果目前沒有修改任何檔案並儲存,那 output 結果會是空的)</span>
$ git diff
<span class="comment"># 比較某個檔案和上一個 commit 作的更動</span>
$ git diff [檔案的相對路徑]
<span class="comment"># 比較兩個 branch 的更動</span>
$ git diff [branch1] [branch2]
</code></pre>
<h2 id="section-9">9. ignore 相關</h2>
<pre><code>
<span class="comment"># 暫時忽略已經 tracked 的檔案</span>
git update-index --assume-unchanged path/to/file
<span class="comment"># 解除忽略已經 tracked 的檔案</span>
git update-index --no-assume-unchanged path/to/file
<span class="comment"># 在 local 設定不要推上 remote 的檔案</span>
<span class="comment"># -> 在 .git/info/exclude 新增檔案</span>
</code></pre>
<h2 id="section-10">10. rebase 相關</h2>
<pre><code>
<span class="comment"># rebase</span>
<span class="comment"># pull 目前 master 的進度</span>
$ git pull origin master
<span class="comment"># merge origin branch</span>
$ git pull origin master --no-rebase
<span class="comment"># merge 到一半,要捨棄目前的 merge</span>
$ git reset --hard ORIG_HEAD
</code></pre>
<h2>11. config 相關</h2>
<pre><code>
<span class="comment"># 依照 commit date 排序顯示 branch list</span>
$ git config --global branch.sort -committerdate
<span class="comment"># 依照版本號順序顯示 tag list</span>
$ git config --global tag.sort -version:refname
</code></pre>
<ul>
<li><a href="index.html">Aucer Main Page</a></li>
</ul>
</body>
</html>