# Git【凡人修G傳之指意化形篇】<font color=#EE82EE size=3>幻形幻影,隨心所欲</font> ## Git 基礎知識 [Git【凡人修G傳之築基篇】](https://hackmd.io/@UmEXPPDuRqO4GLkq657i-g/BJHkx00HF) --- ## 安裝環境 [<img src="https://gitforwindows.org/img/git_logo.png" width=40>](https://gitforwindows.org/) [Git Bash](https://gitforwindows.org/) - Git CLI (命令視窗) [<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/88/TortoiseGit_logo.svg/70px-TortoiseGit_logo.svg.png" width=40>](https://tortoisegit.org/download/) [TortoiseGit](https://tortoisegit.org/download/) - 主要用於顯示檔案狀態 [<img src="https://wac-cdn.atlassian.com/dam/jcr:81b15cde-be2e-4f4a-8af7-9436f4a1b431/Sourcetree-icon-blue.svg?cdnVersion=41" width=40>](https://www.sourcetreeapp.com/) [Sourcetree](https://www.sourcetreeapp.com/) - Git GUI (圖形介面) [<img src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Visual_Studio_Code_1.35_icon.svg/512px-Visual_Studio_Code_1.35_icon.svg.png" width=40>](https://code.visualstudio.com/download) [VS Code](https://code.visualstudio.com/download) - 主要作為 Diff 與 Merge 工具 (Support Excel view by Excel Viewer Plugin) ## Sourcetree + VS Code <font color=#FF4040 size=3>(先安裝, 後配置)</font> Open Sourcetree -> Tools -> Options -> Diff Tab ``` Step1. > Choose "Custom" for the "External Diff Tool" and "Merge Tool" Step2. > 【Diffing】: The "Diff Command" => C:\Users\<UserName>\AppData\Local\Programs\Microsoft VS Code\Code.exe The "Arguments" => --diff --wait "$LOCAL" "$REMOTE" Step3. > 【Merging】: The "Merge Command" => C:\Users\<UserName>\AppData\Local\Programs\Microsoft VS Code\Code.exe The "Arguments" => -n --wait "$MERGED" ``` [<img src="https://i.imgur.com/jHvoliL.png">](https://i.imgur.com/jHvoliL.png) --- ## Git 一般版控 <font color=#FF4040 size=3>(SOP)</font> #### Git 一般SOP【方法一】 ###### 方法一. 先【Stash 隱藏目前工作】再【更新 + 合併】, 最後【Add + Commit】 + 【同步上傳】: ###### <font color=#FF0000>※ 功能製作一半時,但是遠端已有新項目更新需要搭配使用 <font color=#000FF>(但是是否要繼續`git add .` => `git commit` => `git push`看個人)</font>,則選擇【方法一】。</font> ``` > git status . > git stash > git pull origin master --rebase // 如有衝突則...手動修復合併... > git stash pop > git add . > git commit -m "Your Commit" > git push origin master ``` #### GUI如下 (方法一)【幻化為形】 <iframe width="732" height="490" src="https://www.youtube.com/embed/dopGcSaYMrU" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> --- #### ※ Git 一般SOP【方法二】 ###### 方法二. 先【Add + Commit】再【更新 + 合併】, 最後【Add + Commit】 + 【同步上傳】: ###### <font color=#FF0000>※ 無例外的話,確定功能都完成了,單純進行合併並且更新至遠端,則選擇【方法二】。</font> ``` > git status . > git add . > git commit "Your Commit" // 如有衝突則...手動修復合併... > git pull origin master --rebase > git add . > git rebase --continue // 完成合併後,會自動開啟 vim,如需要則可以在原有的 commit 添加說明...無的話直接 => :q! > git push origin master ``` #### ※ GUI如下 (方法二)【幻化為形】 <iframe width="732" height="490" src="https://www.youtube.com/embed/nULQ2GJMARw" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> --- ## Git 分支版控 <font color=#FF4040 size=3>(SOP)</font> #### Git 分支合併SOP ###### 將完成功能的`devBranch`分支合併至`master`中,以下: ``` // 開始新增功能修改等等...完成後 (額外: 如果要直接以 master 進行合併也可) > git checkout devBranch > git add . > git commit "Your Commit" // 如有衝突則...手動修復合併... > git rebase master > git add . > git rebase --continue // 完成合併後,會自動開啟 vim,如需要則可以在原有的 commit 添加說明...無的話直接 => :q! // 此時 devBranch 已經完成更新與合併 > git checkout master > git merge devBranch // 將 devBranch 合併至 master 完成後... > git push origin master ``` ##### 以上如果<font color=#FF006F>分支整併完畢後</font>,依照需求如要刪除已合併分支則刪除,如果<font color=#FF006F>沒有要刪除 `devBranch` 分支,但是要更新的話</font>,以下。 ``` > git push origin devBranch // 進行該分支的遠端更新 ``` #### ※ GUI如下 (分支合併)【幻化為形】 <iframe width="732" height="490" src="https://www.youtube.com/embed/8VPYBnZLKPg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe> ---
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up