<h1>Git 語法</h1> **初始化 repo** ``` git init ``` **查看目前狀態** ``` git status ``` **下載遠端的專案檔案** ``` git clone + 網址 ``` ``` ex: git clone https://WPGH@dev.azure.com/WPGH/OSU%20Micro%20SaaS/_git/Java-flow-web ``` **暫存變更(指定檔案)** ``` git add + 檔案名稱 ``` ``` ex: git add doc-co-filing-form.component.ts ``` **暫存全部變更** ``` git add . ``` **取消暫存變更(指定檔案)** ``` git reset -- 檔案名稱 ``` ``` ex: git reset -- doc-co-filing-form.component.ts ``` **取消全部暫存變更** ``` git reset ``` **保存進度(存檔)** ``` git commit -m "想要的commit訊息" ``` ``` -m 是 Message 的縮寫,直接在後面寫下這次的commit訊息 ``` ``` ex : git commit -m "修改登入頁面的按鈕顏色" ``` **修改 commit 訊息(針對最新的commit)** ``` git commit --amend -m "修改後正確的訊息" ``` **把檔案回到上一個暫存的狀態(還原/放棄修改)** ``` git checkout -- 檔案 ``` ``` ex: git checkout -- doc-co-filing-form.component.ts ``` **查看目前的連線的遠端伺服器名稱** ``` git remote ``` ![image](https://hackmd.io/_uploads/SJwjMbLLbg.png) **查看目前的連線狀態** ``` git remote -v ``` ![image](https://hackmd.io/_uploads/Hy44El8UWe.png) ``` -v 是 --verbose 的縮寫,代表詳細資訊 ``` **建立新 branch 並切換過去** ``` git checkout -b + branch名稱 ``` ``` -b 是 -branch 的縮寫 ``` ``` ex: git checkout -b testBranch ``` ``` git branch + 名稱(建立分支) git checkout + 名稱(切換過去) ``` **回到上一次提交前的狀態** ``` git reset --soft HEAD~1 commit 會消失,但改好的程式碼會留在「暫存區」。只需要修改一下直接再 commit 即可 ``` ``` git reset --hard HEAD~1 commit 會消失,改好的程式碼會「直接消失」! ``` **將雲端上最新的程式碼抓下來** ``` git pull origin dev ``` ``` origin:遠端伺服器(Azure 雲端)的暱稱 dev:告訴 Git 要針對雲端上的哪一個分支進行同步 ``` ``` git pull = git fetch + git merge ``` **將已經 commit 好的進度,推送到雲端分支** ``` git push origin dev ``` **將某個點剪到另一個 branch 上** ``` git cherry-pick + commit位址 ``` ![image](https://hackmd.io/_uploads/BkC383ybC.png) **暫存還沒 commit 的修改** ``` git stash save + "暫存訊息" ``` ``` ex: git stash save "正在開發某某功能到一半" ``` **套用暫存的修改** ``` step1: 找出暫存訊息對應的編號 git stash list ``` ![image](https://hackmd.io/_uploads/rklbT1w8-l.png) ``` step2: 套用指定編號 git stash apply stash@{數字} -> 套用並保留 stash 記錄 git stash pop stash@{數字} -> 套用並刪除 stash 記錄 ```