# [Git] 指令表 [TOC] ## branch name main:分支預設名稱 *原本預設為master HEAD:指著目前所在分支的指標 ### git alias 縮寫 - co:checkout - rb:rebase - rs:reset - br:branch - st:status ## 指令表 | 指令 | 說明 | | -------- | -------- | | `git --version` | 查詢版本 | | `git config --global user.name "java016"` | 使用者設定(帳號) | `git config --global user.email "java016@gmail.com"` | 使用者設定(e-mail) | `git config --list` | 使用者清單 | `git config --global http.sslVerify false` | Git 自簽憑證問題處理 | | `pwd` | 顯示目前所在的路徑| | `ls [-al]`| 列出目前資料夾所有檔案 ( -al 顯示隱藏檔案) | | `cd 資料夾名稱 / [..]` | 切換到某一個資料夾( cd\.\. 跳回上一個資料夾) | | `cd ∼` | 回到最上層 | | `touch 檔案名` | 新增一個檔案 | | `mv 檔案 ../檔案` | 移動檔案到某的地方/改名 | |`mkdir / rmdir 資料夾` | 新增資料夾/刪除『空』資料夾 | | `rm [-f] 檔案名` | 刪除一個檔案(-f 表示強制刪除) | | `rm -rf 資料夾` | 刪除『有檔案的』資料夾 ( -r 代表刪除子資料夾) | | `clear` | 清空Command Line的畫面 | | `git init` | 初始化Git | | `git status` | 查看Git目前在工作區與暫存區的狀況 | | `git add` | 把所有檔案交給Git控管 | | `git add 檔案名稱` | 把新增、更改後的版本交給Git控管 | | `git commit -m "訊息"` | 新增歷史紀錄(把暫存區的檔案存到本地儲存庫) | | `git commit` | 新增歷史紀錄(把檔案存入本機端儲存庫) | | `git show commitID` | 檢視某一個commit的修改狀況 | | `git checkout commitID` | 將HEAD切換到某一個commit | | `git log` | 檢視所有的commit(詳細) | | `git log —oneline` | 檢視所有的commit(單行) | | `git log [--oneline] 檔案` | 檢視某個檔案的所有commit(詳細) | | `git log -p 檔案` | 檢視某個檔案的所有修改的狀況 | | `git tag 標籤名稱 commitID` | 將某一個commit貼上標籤名稱 | | `git tag` | 查看所有標籤 | | `git tag -d 標籤名稱` | 刪除標籤名稱 | | `git commit —amend` | 修改最後一個commit的備註 | | `git revert` | 取消某一個commit的記錄 | | `git reset --hard commitID` | 回到某一個commit重新開始(清空後面的紀錄) | | `git reset --soft commitID` | 回到某一個commit重新開始(保留後面的紀錄) | | `git rebase -i commitID` | 編輯、刪除某幾個commit | | `git rebase —abort` | 中斷rebase | | `git rebase —continue` | 繼續rebase | | `git branch [-a]` | 查看現有分支(本機端) (-a 連遠端Github的branch也一起顯示) | | `git branch 分支名稱` | 新增分支,依然在原本的分支 | | `git checkout 分支名稱` | 切換分支 | | `git checkout -b 分支名稱` | 新增分支後︐切換到新增的分支 | | `git checkout -b 分支名稱 遠端分支` | 複製遠端分支到本地端 | | `git branch -D 分支名稱` | 刪除某一分支| | `git cherry-pick commitID` | 撿取某個commit到目前的分支 | | `git merge 分支名稱` | 合併某個分支到目前的分支 | | `git remote -v` | 查看連接遠端Github Repository的資料庫 | | `git remote add origin 遠端Repo網址` | 設定本地端連接至遠端的資料庫 | | `git remote rm origin 遠端Repo網址` | 移除本地端連接至遠端的資料庫 | | `git push origin 本機分支 [-f]` | 本地端推送資料至遠端(Github) (-f 強制推送) | | `git push [-u] origin 本機分支` | 本地端推送資料至遠端並記住分支設定 (-u 第一次推送) | | `git push` | 本地端推送資料至遠端(之後推送) | | `git pull origin 遠端分支` | 本地端拉取遠端(Github)的資料 | | `git clone 遠端Repo網址` | 把Github專案複製下載一份到自已的電腦裡 | | `ssh-keygen -t rsa -C "your e-mail"` | 用 rsa 演算法建立公鑰/私鑰 | | `專案目錄\.gitignore` | 忽略某些檔案不進版本控制 | | `git rm --cached` | 如果檔案已經被git控管過,不想再被git控管 | ## Commit Message ### Header: `<type>(<scope>): <subject>` - #### type 代表 commit 的類別:feat, fix, docs, style, refactor, test, chore,必要欄位。 | type | explain | | ---- | ------- | | feat | 新增/修改功能 (feature) | | fix | 修補 bug (bug fix) | | docs | 文件 (documentation) | | style | 格式 (不影響程式碼運行的變動 white-space, formatting, missing semi colons, etc) | | refactor | 重構 (既不是新增功能,也不是修補 bug 的程式碼變動) | | perf | 改善效能 (A code change that improves performance) | | test | 增加測試 (when adding missing tests) | | chore | 建構程序或輔助工具的變動 (maintain) | | revert | 撤銷回覆先前的 commit 例如:revert: type(scope): subject (回覆版本:xxxx) | - #### scope 代表 commit 影響的範圍,例如資料庫、控制層、模板層等等,視專案不同而不同,為可選欄位。 - #### subject 代表此 commit 的簡述,不超過 50 個字元,結尾不要加句號,為必要欄位。 ### Body: 72-character wrapped. This should answer: - Body 部份是對本次 Commit 的詳細描述,可以分成多行,每一行不要超過 72 個字元。 - 說明程式碼變動的項目與原因,還有與先前行為的對比。 ### Footer: - 填寫任務編號(如果有的話). - BREAKING CHANGE(可忽略),記錄不兼容的變動,以 BREAKING CHANGE: 開頭,後面是對變動的描述、以及變動原因和遷移方法。 ## 遇到的問題 ### 刪除沒有完成發布版本的分支 (release/xxx) 時產生錯誤,並且無法強制刪除 - 部分錯誤訊息: >git -c diff.mnemonicprefix=false -c core.quotepath=false --no-optional-locks branch -D - 原因: 尚無查明 - 解決: 將該分支取消追蹤,並更改分類名稱(不使用 release),再做刪除即可。
×
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