[筆記] Git 常用命令大全(按場景分類)

適用於日常開發中對 Git 的常見操作。透過分類整理,幫助你快速上手或查閱。 📦 基礎指令 指令 用途 git init 初始化一個 Git 儲存庫(建立 .git 資料夾)。 git clone <url> 將遠端儲存庫複製到本地。 git status 查看目前工作目錄狀態(檔案修改、暫存等)。 git add <file> 將檔案新增到暫存區。 git commit -m "message" 提交暫存區檔案到本地儲存庫,並新增提交訊息。 git log 查看提交歷史。 🌱 分支管理 指令 用途 git branch 查看本地分支列表。 git branch <branch-name> 建立一個新分支。 git checkout <branch-name> 切換到指定分支。 git switch <branch-name> 切換到指定分支(推薦使用的新指令)。 git merge <branch-name> 將指定分支合併到目前分支。 git branch -d <branch-name> 刪除已合併的分支。 git branch -D <branch-name> 強制刪除分支。 🌍 遠端儲存庫操作 指令 用途 ...

2025年6月2日 · 2 min · MoeJue

[筆記]Git常用命令大全

繼上一次之後,我抽空整理了一份比較完整的 Git 常用命令清單,並找到了一張非常棒、非常高清的導圖(1759*3162)。 查看、新增、提交、刪除、找回、重置修改檔案 git help <command> # 顯示 command 的說明 git show # 顯示某次提交的內容 git show $id git co -- <file> # 捨棄工作區修改 git co . # 捨棄工作區修改 git add <file> # 將工作檔案修改提交到本地暫存區 git add . # 將所有修改過的工作檔案提交暫存區 git rm <file> # 從版本庫中刪除檔案 git rm <file> --cached # 從版本庫中刪除檔案,但不刪除檔案 git reset <file> # 從暫存區恢復到工作檔案 git reset -- . # 從暫存區恢復到工作檔案 git reset --hard # 恢復最近一次提交過的狀態,即放棄上次提交後的所有本次修改 git ci <file> git ci . git ci -a # 將 git add, git rm 和 git ci 等操作都合併在一起執行 git ci -am "some comments" ...

2018年6月16日 · 3 min · MoeJue

Git簡單的使用步驟

本文不闡述任何概念性知識,僅僅只是做一個筆記,簡單的使用步驟,如遇障礙,請Google一下 使用SSH 完成 Git 與 GitHub 的綁定 生成 SSH key ssh-keygen -t rsa 指定 RSA 演算法生成金鑰,之後就會生成兩個檔案,分別為id_rsa和id_rsa.pub,即私鑰id_rsa和公鑰id_rsa.pub。對於這兩個檔案 添加 SSH key github.com -> Settings -> SSH and GPG -> New SSH key 將公鑰id_rsa.pub的內容貼到Key處的位置(Titles的內容不填寫也沒關係),然後點擊Add SSH key 即可。 驗證綁定是否成功 ssh -T git@github.com 把本地專案推送到github的命令 (1) 打開你的目錄 cd demo (2) 初始化版本庫,用於生成git檔案 git init (3) 將所有檔案添加到暫存區 git add * (4) 提交目前工作空間的修改內容 git commit -m "first commit" (5) 將儲存庫連接到遠端伺服器 git remote add origin <server>(就是上面你儲存庫的地址) (6) 將改動推送到所添加的伺服器上 git push -u origin master 在推送的時候如果出現如下錯誤: warning: redirecting to https://github.com/178146582/dabai.git/ To http://github.com/178146582/dabai.git ! [rejected] master -> master (fetch first) error: failed to push some refs to 'http://github.com/178146582/dabai.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. 查了一下錯誤的原因是github中的README.md檔案不在本地程式碼目錄中。所以我們把上面第六步分成兩步: ...

2018年4月3日 · 1 min · MoeJue