Git 為一個版本控制 system Git 常用指令 ``` * git init -> git 初始化 ( 會在當前資料夾建立一個 .git 的資料夾 ) * git config -> 設定資訊 * git config --list -> 列出目前的設定資訊 * git status -> 檢視狀態 * git add "file name" * git add . * git commit -m "messages" ``` git 檔案生命流程 ( local ) ![](https://hackmd.io/_uploads/Sk5Xwhn53.png) 之後要上傳 ( push ) 或下載 ( pull ) 至遠端 ( e.g. GitHub ) Git 其他指令 ``` * git log * git restore * git help * git blame "file name" ``` Git 上關於分支 ( branch ) 可以把分支想像為一平行時空,user 可以再做某些其他嘗試時候建立一個分支 在分支上進行修改等等的嘗試,同時間也可以有很多分支 Git 分支常用指令 ``` * git branch -> 檢視分支列表 * git branch "branch name" -> 創造一個分支 * git branch -d "branch name" -> 刪除某個分支 * git switch "branch name" -> 移動到某個分支 ( 移動到 commit 點也可以,後面要 + --detach ) * git merge "branch name" -> 將現在所在的分支與目標分支做合併 * git rebase "branch name" -> 另一種合併方法,概念類似接肢 * git reset "目的地" ( 預設為 mixed ) --mixed -> 將 rollback 回去後 commit 內的變動移至 working area ( 待 add ) --soft -> 將 rollback 回去後 commit 內的變動移至 staging area ( 待 commit ) --hard -> 將 rollback 回去後 commit 內的變動全數刪除 目的地可以為一個 branch, commit id, 代名詞 e.g. git reset HEAD^ -> 回上一步 git reset HEAD~n -> 回上 n 步 git reset d958 -> 回到 commit id git reset Cat -> 回到某個 branch * git reflog -> 檢視 HEAD 的移動紀錄 ```