[TOC] --- ## SourceTree 下載連結 https://www.sourcetreeapp.com/ ![](https://hackmd.io/_uploads/SJ4NoC2Fn.png) --- ## SourceTree 安裝 點擊剛下載的檔案 ![](https://hackmd.io/_uploads/SysWhC2F2.png) ![](https://hackmd.io/_uploads/HkHrn0ntn.png) ![](https://hackmd.io/_uploads/ryeHaCnth.png) ![](https://hackmd.io/_uploads/rkOua03Yh.png) --- ## SourceTree 創建Local專案 ![](https://hackmd.io/_uploads/Hy34y16t3.png) ![](https://hackmd.io/_uploads/rynKk1pth.png) --- ## Git Create SSH key 打開SourceTree上的Terminal ![](https://hackmd.io/_uploads/BkjrZ16th.png) 查看Git指令是否有效 ``` terminal git --version ``` ![](https://hackmd.io/_uploads/SyVmz16Fn.png) ``` terminal ssh-keygen -t rsa -C "自訂字串" ``` ![](https://hackmd.io/_uploads/S1_xN1TKh.png) 全部直接按Enter ![](https://hackmd.io/_uploads/BJk54kTYn.png) --- ## Gitlab SSH key 設定 ``` terminal cat /c/Users/${username}/.ssh/id_rsa.pub ``` ![](https://hackmd.io/_uploads/ryuGOkTY2.png) 複製完後 登入Gilab設定SSH key ![](https://hackmd.io/_uploads/BJXpuJ6tn.png) 將剛剛都字串複製到 Key裡面後 Add key ![](https://hackmd.io/_uploads/SJOmYJat3.png) --- ## SourceTree SSH key & Remote 設定 ![](https://hackmd.io/_uploads/rkjick6Fh.png) ![](https://hackmd.io/_uploads/rys_i1pK2.png) ![](https://hackmd.io/_uploads/H1U6sJaY3.png) ![](https://hackmd.io/_uploads/HyAbhk6t2.png) ![](https://hackmd.io/_uploads/HkMH21aKh.png) ![](https://hackmd.io/_uploads/S12w2yTF2.png) ![](https://hackmd.io/_uploads/r1cqnyaK3.png) ![](https://hackmd.io/_uploads/BJJxaJTt2.png) --- ## 建立分支 ![](https://hackmd.io/_uploads/BJK-QepY3.png) ![](https://hackmd.io/_uploads/ryKP7l6Y3.png) ![](https://hackmd.io/_uploads/rJKlbGaKh.png) --- ## 切換分支 需確認是否有異動檔案,若有異動會造成無法切換 點擊要切換之分支 ![](https://hackmd.io/_uploads/rklO-mMpKn.png) 詢問是否要將異動項目移至要切換的分支,或是打勾Clean(清除所有異動) ![](https://hackmd.io/_uploads/ryfw7zTYh.png) 切換成功且無清除異動,可於 File Status 查看 ![](https://hackmd.io/_uploads/rJ6t4zat3.png) --- ## Commit 確認commit之分支,Unstaged files 移至 Staged files 輸入下方 ![](https://hackmd.io/_uploads/HyQ5zMaF3.png) 填寫內容並點擊Commit ![](https://hackmd.io/_uploads/BJ2q8M6Fh.png) --- ## Push ![](https://hackmd.io/_uploads/rJGkdf6Fn.png) ![](https://hackmd.io/_uploads/rk8csf6t3.png) ![](https://hackmd.io/_uploads/Skz_3zpYh.png) --- ## Fetch & Pull 點擊Fetch取得最新異動紀錄,若有向下箭頭,代表有資料須更新 ![](https://hackmd.io/_uploads/Skx0AMaYn.png) 點擊Pull更新至最新紀錄 ![](https://hackmd.io/_uploads/HJgN1QaFn.png) --- ## Merge & Pull 點擊要Merge之分支,Merge into current branch ![](https://hackmd.io/_uploads/rJBzW7aFn.png) 點擊Pull更新至最新紀錄 ![](https://hackmd.io/_uploads/S1QvTQpFh.png) --- ## Merge Conflicts ![](https://hackmd.io/_uploads/S1fA1Npt2.png) 發生衝突,須解決衝突再commit ![](https://hackmd.io/_uploads/HybVZNaKh.png) ![](https://hackmd.io/_uploads/H1vdWEat2.png) --- ## Reverse commit 取消此次的 Commit =>[再做一個新的 Commit,來取消你不要的 Commit] ![](https://hackmd.io/_uploads/HJ-E846th.png) ![](https://hackmd.io/_uploads/HJo4H4TK3.png) ![](https://hackmd.io/_uploads/H1QIcETYh.png) --- ## Reset 想要退 Commit,就在想要去的 Commit 上按滑鼠右鍵,選擇「Reset master to this commit」 ![](https://hackmd.io/_uploads/H17JoVTKn.png) Soft:將退回commit的紀錄存於staged files,本身尚未commit的異動不變 Mixed:將 staged files 退回 unstaged files,再將unstaged files 與 Reset files 混合 Hard:此commit之後的所有紀錄清除 ![](https://hackmd.io/_uploads/B1GbVVpY2.png) ![](https://hackmd.io/_uploads/SyUqNH6Yn.png) ![](https://hackmd.io/_uploads/HyQ3NB6K2.png) --- ## Cherry Pick 某個分支的某幾個 Commit ![](https://hackmd.io/_uploads/SyBCt7RYh.png) ![](https://hackmd.io/_uploads/rykQq70tn.png) ![](https://hackmd.io/_uploads/B1QP9mRF2.png) ![](https://hackmd.io/_uploads/H13ri7CF3.png) --- ## Rebase 用來整理、編輯還沒有推出去的 Commit ![](https://hackmd.io/_uploads/r1TkOERK2.png) ![](https://hackmd.io/_uploads/Hy24ZBCF3.png) 與前一筆commit合併 ![](https://hackmd.io/_uploads/r1e1kGH0F2.png) 勾選Amend Commit 需改寫Message內容 ![](https://hackmd.io/_uploads/r11rGHCFn.png) ![](https://hackmd.io/_uploads/rJZufHRY2.png) 改寫後送出,僅剩一筆新的COMMIT ![](https://hackmd.io/_uploads/HyRozHRt3.png) ![](https://hackmd.io/_uploads/r1x0zrAY3.png)