* git init 建立新的本地端 Repository。 * git clone [Repository URL] 複製遠端的 Repository 檔案到本地端。 * git status 檢查本地端檔案異動狀態。 * git add [檔案或資料夾] 將指定的檔案(或資料夾)加入版本控制。 * git add -p [檔案或資料夾] 可指定要加入的異動,(y, n, s, e)。 * git commit 提交(commit)目前的異動 (50/72 Rule)。 第一行應該要摘要該次修改的目的,第二行直接換行,而在第三行以後才詳細闡述(問題/原因/解法) * [git commit --amend](https://backlog.com/git-tutorial/tw/stepup/stepup7_1.html) 改寫上一次提交的訊息內容。 * git push origin [BRANCH_NAME] 發佈至遠端指定的分支(Branch) * git log 查看先前的 commit 記錄。 * git branch -a 查看分支。 * git branch [BRANCH_NAME] 建立分支。 * git checkout [BRANCH_NAME] 取出指定的分支。 * git checkout -b [BRANCH_NAME] 建立並跳到該分支 (等於git branch + git checkout) * git branch -D [BRANCH_NAME] 強制刪除指定分支(須先切換至其他分支再做刪除)。 * git reset --hard [HASH] 強制恢復到指定的 commit(透過 Hash 值)(所有修改全部消失)。 * git checkout [HASH] 切換到指定的 commit(與 git checkout [BRANCH_NAME] 相同)。 * git stash 獲取目前工作目錄的 dirty state,並保存到一個未完成變更的 stack,以方便隨時回復至當初的 state。 * [Merge a Git Branch into Master](https://backlog.com/git-tutorial/tw/stepup/stepup1_4.html) * Switching to master Switch to the master branch by running git checkout (先切到本地的master): **git checkout master** * Pulling changes Get the latest changes from master by using git pull: (將本地的master拉到最新,跟remote master 同步) **git pull origin master** * Merging changes Then merge the changes with the git merge command:(合併本地master與開發的branch) **git merge [BRANCH_NAME] --no-ff** * Fix conflicts 解決衝突 **git mergetool** ![](https://camo.githubusercontent.com/67f3534844a18c78f0975052fbc39ccc976e591fa5f5ca6c2602f62caac63e6c/68747470733a2f2f6170702e626f782e636f6d2f726570726573656e746174696f6e2f66696c655f76657273696f6e5f33373636313934383539342f696d6167655f323034382f312e706e673f7368617265645f6e616d653d7773393269753166746a69623870636d71306238686c79306877776e62316a68) Ctrl w + h # move to the split on the left Ctrl w + j # move to the split below Ctrl w + k # move to the split on top Ctrl w + l # move to the split on the right :diffg RE # get from REMOTE :diffg BA # get from BASE :diffg LO # get from LOCAL **git add** **git commit** * Pushing changes The final step is pushing local changes to the remote repository : **git push origin master** * git config --global user.name "Your Name" git config --global user.email "you@example.com" 設定使用者 * git config --global core.editor **vim** 設定commit message編輯器為vim * git config --global merge.tool **vimdiff** 設定git merge的工具 * git config --global color.ui **true** 設定UI顏色 * git config --global alias.xx yy 設定指令別名(減少打字) ``` 例如: git status git config --global alias.st status git st <== 之後等於git status ``` * 所有設定都會保在~/.gitconfig內 ``` vim ~/.gitconfig [user] name = Your Name email = you@example.com [core] editor = vim [merge] tool = vimdiff [color] ui = true ``` * .gitignore 不想放在git裡面的檔案的規則。 https://github.com/github/gitignore