初始化仓库 | git init | |
克隆远程仓库 | git clone <url> | |
查看工作区状态 | git status | |
添加文件到暂存区 | git add <file> | |
添加所有修改到暂存区 | git add . | |
提交暂存区 | git commit -m "msg" | |
修改上次提交 | git commit --amend | |
查看简洁提交历史 | git log --oneline | |
查看未暂存的修改 | git diff | |
查看已暂存的修改 | git diff --staged |
列出本地分支 | git branch | |
创建新分支 | git branch <name> | |
切换分支 | git checkout <branch> | |
创建并切换分支 | git checkout -b <branch> | |
切换分支(新语法) | git switch <branch> | |
合并分支到当前 | git merge <branch> | |
删除已合并分支 | git branch -d <branch> | |
强制删除分支 | git branch -D <branch> | |
变基到目标分支 | git rebase <branch> | |
暂存当前修改 | git stash | |
恢复暂存修改 | git stash pop |
查看远程仓库 | git remote -v | |
添加远程仓库 | git remote add origin <url> | |
拉取远程更新(不合并) | git fetch | |
拉取并合并远程更新 | git pull | |
推送到远程 | git push | |
推送并设置上游 | git push -u origin <branch> | |
强制推送(谨慎使用) | git push --force |
撤销工作区修改 | git restore <file> | |
取消暂存 | git restore --staged <file> | |
回退一个提交(保留修改) | git reset HEAD~1 | |
硬回退一个提交 | git reset --hard HEAD~1 | |
创建反向提交 | git revert <commit> | |
删除未跟踪的文件和目录 | git clean -fd |
列出所有标签 | git tag | |
创建轻量标签 | git tag v1.0.0 | |
创建附注标签 | git tag -a v1.0.0 -m "msg" | |
推送所有标签 | git push origin --tags |
查看提交详情 | git show <commit> | |
查看文件每行修改者 | git blame <file> | |
图形化提交历史 | git log --graph --oneline | |
查看操作历史 | git reflog | |
按作者统计提交数 | git shortlog -sn |
基础命令init、add、commit、status、log 等日常高频命令
分支管理branch、checkout、merge、rebase 等分支操作
远程仓库remote、fetch、pull、push 等远程协作命令
撤销操作reset、revert、stash、clean 等撤销和暂存命令
支持搜索命令或中文描述