@@ -1484,7 +1484,7 @@ v2 分支中的 log 如下,我想要它的 553587b - add f.py這個 commit
1484
1484
1485
1485
假設我 commit history 為 A1 -> A2 -> A3 -> A4 -> A5 -> A6
1486
1486
1487
- 我現在想要回 A4 這個 commit , 這時候我就可以使用 git revert !!
1487
+ 我現在想要回 A4 這個 commit , 這時候我就可以使用 git revert !!
1488
1488
1489
1489
先 revert A6
1490
1490
@@ -1504,10 +1504,16 @@ A1 -> A2 -> A3 -> A4 -> A5 -> A6 -> A6_revert -> A5_revert
1504
1504
1505
1505
這時候,其實你的 commit 就是在 A4 這個位置 。
1506
1506
1507
- 使用 git revert 的好處,就是可以保留 commit history , 萬一你又後悔了,
1507
+ 使用 git revert 的好處,就是可以保留 commit history, 萬一你又後悔了,
1508
1508
1509
1509
也可以在 revert 回去。
1510
1510
1511
+ 如果你想要 revert 最新的 commit, 只需要使用 HEAD
1512
+
1513
+ ``` cmd
1514
+ git revert HEAD
1515
+ ```
1516
+
1511
1517
## 解決衝突
1512
1518
1513
1519
在進行合併的時候,有時候會顯示出 ** 衝突conflicts** ,這時候就必須手動解決衝突後再送出。
@@ -1817,6 +1823,81 @@ git grep "hello"
1817
1823
1818
1824
其他更詳細的介紹,請參考 [ https://git-scm.com/docs/git-grep ] ( https://git-scm.com/docs/git-grep )
1819
1825
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
+
1820
1901
## git Submodule
1821
1902
1822
1903
由於這個內容稍微比較多,所以我另外寫了一篇,
@@ -1936,6 +2017,10 @@ git config --global alias.br branch
1936
2017
git config --global alias.ck checkout
1937
2018
```
1938
2019
2020
+ ``` cmd
2021
+ git config --global alias.sw switch
2022
+ ```
2023
+
1939
2024
``` cmd
1940
2025
git config --global alias.cm commit
1941
2026
```
@@ -2108,7 +2193,7 @@ git remote set-url origin git@blue.github.com:blue-rubiks/t11.git
2108
2193
2109
2194
* [ 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 )
2110
2195
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 )
2112
2197
2113
2198
[ PR (Pull Request) 教學] ( https://github.com/twtrubiks/Git-Tutorials/tree/master/pr-tutorial )
2114
2199
0 commit comments