Git常用指令

  1. 查看分支/目前分支
    git branch
  2. 新增分支
    git branch <分支名稱>
  3. 刪除分支
    git branch -d <分支名稱>
  4. 切換分支
    git checkout <分支名稱>
  5. 拉取origin分支資料,等同於執行git fetch + gti merge 目前的分支
    git pull
  6. 推送分支到遠端, ex.git push origin leohuang
    git push <數據庫簡稱> <分支名稱>
  7. 合併分支
    git merge <分支名稱>
  8. 查看提交紀錄
    git log
  9. 查看目前檔案狀態
    git staus
  10. 單一檔案加入索引
    git add <檔案名稱>
  11. 全部加入索引
    git add -A
    git add -all
  12. 提交紀錄
    git commit -m "<填寫版本更新資訊>"
  13. 合併提交, 將第二行的 "pick" 改為 "squash",儲存後並退出
    git rebase -i HEAD~~
  14. 查看圖形多分支顯示的提交紀錄指令
    git log --all --graph --decorate --oneline
  15. 註冊縮短指令
    git config --global alias.<自訂命令> <原始命令>
  16. 縮短checkout
    git config alias.co checkout
  17. 縮短branch
    git config alias.br branch
  18. 縮短commit
    git config alias.ci commit
  19. 縮短stasus
    git config alias.st status
  20. 縮短美化後的git log樣式(斷行是為了文章方便閱讀,實際上不能斷行)
    git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset
    -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"