Skip to content

Commit 8a448e5

Browse files
committed
git clean tutorial
1 parent 43d83c0 commit 8a448e5

File tree

2 files changed

+110
-3
lines changed

2 files changed

+110
-3
lines changed

README.md

+88-3
Original file line numberDiff line numberDiff line change
@@ -1484,7 +1484,7 @@ v2 分支中的 log 如下,我想要它的 553587b - add f.py這個 commit
14841484

14851485
假設我 commit history 為 A1 -> A2 -> A3 -> A4 -> A5 -> A6
14861486

1487-
我現在想要回 A4 這個 commit , 這時候我就可以使用 git revert !!
1487+
我現在想要回 A4 這個 commit , 這時候我就可以使用 git revert !!
14881488

14891489
先 revert A6
14901490

@@ -1504,10 +1504,16 @@ A1 -> A2 -> A3 -> A4 -> A5 -> A6 -> A6_revert -> A5_revert
15041504

15051505
這時候,其實你的 commit 就是在 A4 這個位置 。
15061506

1507-
使用 git revert 的好處,就是可以保留 commit history , 萬一你又後悔了,
1507+
使用 git revert 的好處,就是可以保留 commit history, 萬一你又後悔了,
15081508

15091509
也可以在 revert 回去。
15101510

1511+
如果你想要 revert 最新的 commit, 只需要使用 HEAD
1512+
1513+
```cmd
1514+
git revert HEAD
1515+
```
1516+
15111517
## 解決衝突
15121518

15131519
在進行合併的時候,有時候會顯示出 **衝突conflicts** ,這時候就必須手動解決衝突後再送出。
@@ -1817,6 +1823,81 @@ git grep "hello"
18171823

18181824
其他更詳細的介紹,請參考 [https://git-scm.com/docs/git-grep](https://git-scm.com/docs/git-grep)
18191825

1826+
## git clean
1827+
1828+
刪除未被追蹤的檔案,
1829+
1830+
`git clean -n`
1831+
1832+
`-n, --dry-run` Don’t actually remove anything, just show what would be done
1833+
1834+
這個指定是告訴你會刪除哪些資料, 不會真的刪除.
1835+
1836+
範例如下,
1837+
1838+
```cmd
1839+
❯ git status
1840+
On branch master
1841+
1842+
No commits yet
1843+
1844+
Untracked files:
1845+
(use "git add <file>..." to include in what will be committed)
1846+
test.py
1847+
1848+
nothing added to commit but untracked files present (use "git add" to track)
1849+
1850+
❯ git clean -n
1851+
Would remove test.py
1852+
```
1853+
1854+
如果你執行以下的指令, 就會真的刪除,
1855+
1856+
`git clean -df`
1857+
1858+
詳細說明可使用 `git clean --help` 觀看,
1859+
1860+
範例如下,
1861+
1862+
```cmd
1863+
❯ git status
1864+
On branch master
1865+
1866+
No commits yet
1867+
1868+
Untracked files:
1869+
(use "git add <file>..." to include in what will be committed)
1870+
test.py
1871+
1872+
nothing added to commit but untracked files present (use "git add" to track)
1873+
1874+
❯ git clean -df
1875+
Removing test.py
1876+
1877+
❯ git status
1878+
On branch master
1879+
1880+
No commits yet
1881+
1882+
nothing to commit (create/copy files and use "git add" to track)
1883+
```
1884+
1885+
還記得前面介紹的 `git reset` 指令嗎, 基本上它可以搭配 `git clean` 一起使用,
1886+
1887+
`git clean` 影響沒有被 track 的檔案
1888+
1889+
`git reset` 影響有被 track 的檔案
1890+
1891+
結合以上, 可以回到一個指定的 commit 乾淨的狀態,
1892+
1893+
```cmd
1894+
git reset --hard HEAD
1895+
git clean -df
1896+
git status
1897+
```
1898+
1899+
建議大家自己操作一下.
1900+
18201901
## git Submodule
18211902

18221903
由於這個內容稍微比較多,所以我另外寫了一篇,
@@ -1936,6 +2017,10 @@ git config --global alias.br branch
19362017
git config --global alias.ck checkout
19372018
```
19382019

2020+
```cmd
2021+
git config --global alias.sw switch
2022+
```
2023+
19392024
```cmd
19402025
git config --global alias.cm commit
19412026
```
@@ -2108,7 +2193,7 @@ git remote set-url origin git@blue.github.com:blue-rubiks/t11.git
21082193

21092194
* [Youtube Tutorial - github PR (Pull Request) 教學](https://youtu.be/bXOdD-bKfkA) - [文章快速連結](https://github.com/twtrubiks/Git-Tutorials/tree/master/pr-tutorial#github-pr-pull-request-%E6%95%99%E5%AD%B8)
21102195

2111-
* [Youtube Tutorial - github CLI PR 教學](https://youtu.be/AD8X11lq3gQ) - [文章快速連結](https://github.com/twtrubiks/Git-Tutorials/tree/master/pr-tutorial#github-cli-pr-%E6%95%99%E5%AD%B8)
2196+
* [Youtube Tutorial - github CLI PR 教學 - gh](https://youtu.be/AD8X11lq3gQ) - [文章快速連結](https://github.com/twtrubiks/Git-Tutorials/tree/master/pr-tutorial#github-cli-pr-%E6%95%99%E5%AD%B8)
21122197

21132198
[PR (Pull Request) 教學](https://github.com/twtrubiks/Git-Tutorials/tree/master/pr-tutorial)
21142199

pr-tutorial/README.md

+22
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,18 @@ github 上面也確實有這個 PR
139139

140140
![alt tag](https://i.imgur.com/7atBIzY.png)
141141

142+
也可以搭配其中的指令
143+
144+
```cmd
145+
gh pr create --base dev -a @me -l bug -r twtrubiks
146+
```
147+
148+
`-a` 代表指定這個 pr 給自己
149+
150+
`-l` label 設定為 bug
151+
152+
`-r` 設定 reviews 為 twtrubiks
153+
142154
除了發 PR 之外, 也可以透過 github CLI 接受 PR, 指令如下
143155

144156
文件可參考 [https://cli.github.com/manual/gh_pr_merge](https://cli.github.com/manual/gh_pr_merge)
@@ -163,6 +175,16 @@ github 上面確實已經合併這個 PR
163175

164176
![alt tag](https://i.imgur.com/h6akTEd.png)
165177

178+
也可以建立 issue [gh_issue_create](https://cli.github.com/manual/gh_issue_create)
179+
180+
```cmd
181+
gh issue create -a @me -l bug
182+
```
183+
184+
`-a` 代表指定這個 issue 給自己
185+
186+
`-l` label 設定為 bug
187+
166188
還有非常多的指令, 就不一一介紹給大家了, 大家請自行研究:relaxed:
167189

168190
基本上, github CLI 功能是非常強大的:smile:

0 commit comments

Comments
 (0)