Git命令參攷

收錄日常開發最常用的Git子命令:初始化、尅隆、分支、合併、stash與遠程操作。 支持蒐索與一鍵複製,適合新手入門與老手偶爾忘命令時查閱。

隱私提示:本地解析,不上傳伺服器。

↓ 在下方輸入區貼上內容,結果會立即顯示

常用 Git 命令速查; 搜索命令或说明,一键复制。

git init

Initialize a new repository

git clone <url>

Clone a remote repository

git status

Show working tree status

git add <file>

Stage changes

git add .

Stage all changes

git commit -m "msg"

Commit staged changes

git push

Push commits to remote

git pull

Fetch and merge remote changes

git branch

List branches

git branch <name>

Create a branch

git checkout <branch>

Switch branch

git switch <branch>

Switch branch (newer)

git merge <branch>

Merge branch into current

git log --oneline

Compact commit history

git diff

Show unstaged diff

git stash

Stash working changes

git stash pop

Apply latest stash

git remote -v

List remotes

git fetch

Download remote objects

git rebase <branch>

Rebase onto branch

註釋說明

说明

收录日常开发最常用的 Git 子命令; 完整选项见 git help 与官方文档。

收錄日常開發最常用的Git子命令:初始化、尅隆、分支、合併、stash與遠程操作。 支持蒐索與一鍵複製,適合新手入門與老手偶爾忘命令時查閱。

快速開始

  1. 瀏覽清單

    按使用頻率整理的常用命令。

  2. 搜尋

    按命令名或說明過濾。

  3. 複製命令

    粘貼到終端執行。

與git help的關係

本頁是速查錶; 完整選項與參數說明請運行git help <command>。

典型工作流

從尅隆倉庫開始:`git clone <url>`將遠程程式碼完整複製到本地。 日常開發中,用`git checkout -b feature-x`創建新分支隔離修改。 完成功能後,`git add .`暫存所有變更,`git commit -m“message”`提交,最後`git push origin feature-x`推送分支。

遇到緊急bug時,用`git stash`臨時保存未提交的修改並清空工作區,切換到主分支修復。 合併時,`git merge --no-ff`保留分支歷史,衝突用`git mergetool`視覺化解决。 定期執行`git fetch --prune`清理遠程已删除分支的本地記錄。

示例

示例

Input

git stash

Output

Stash working changes

FAQ

包含高級命令嗎?

聚焦日常操作; rebase -i、filter-branch等見官方檔案。

需要聯網嗎?

不需要,純靜態參攷頁。

為什麼我尅隆的倉庫沒有.git目錄?

可能使用了`--depth=1`淺尅隆參數,這只會下載最新版本歷史以節省空間。 要獲取完整歷史,重新尅隆時不加該參數,或對現有倉庫執行`git fetch --unshallow`補全歷史。