Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Git 常用指令速查大全:倉庫操作、提交推送、分支管理、標籤、遠端同步

編輯:Linux 教學

取得 Git 倉庫

git init                          # 初始化本地倉庫
git clone git@host:repo.git       # 克隆遠端倉庫
git remote add origin git@host:repo.git  # 新增遠端別名
git remote -v                     # 查看遠端倉庫資訊

提交變更

git add .                         # 暫存所有變更(含新增檔案)
git add -u                        # 暫存已追蹤檔案的修改與刪除
git commit -m "提交說明"          # 本地提交
git push origin master            # 推送至遠端 master 分支
git status                        # 查看工作區狀態

檔案操作

git add readme.txt                # 追蹤新檔案
git rm readme.txt                 # 刪除檔案(含工作區)
git rm --cached readme.txt        # 僅從暫存區移除,保留工作區檔案
git mv readme.txt readme          # 重命名檔案

分支與合併

git branch                        # 列出本地分支
git branch new-feature            # 建立分支
git checkout new-feature          # 切換分支
git checkout -b new-feature       # 建立並切換
git merge new-feature             # 合併分支到當前分支
git branch -d new-feature         # 刪除已合併分支

查看歷史與差異

git log                           # 提交歷史
git log -p                        # 顯示每次提交的差異
git log a..b                      # 查看 a 到 b 之間的提交
git diff                          # 工作區與暫存區差異
git diff --cached                 # 暫存區與上次提交差異

撤銷與恢復

git reset HEAD~1                  # 撤銷最近一次提交(保留變更)
git reflog                        # 查看所有操作記錄(含已刪除提交)
git branch recover-branch <sha>  # 從 reflog 找回丟失提交
Copyright © Windows教程網 All Rights Reserved