Git 速查表
Git 是现代软件开发不可或缺的版本控制工具。本速查表按场景分类整理了最常用的 25+ 个 Git 命令,从基础操作到高级技巧,每个命令都有实际使用示例。无论你是刚开始使用 Git 还是需要快速查阅某个命令,这份速查表都能帮到你。
更新: 2026-07-15·26 条命令
使用场景速查
| 你要做什么 | 用哪个命令 |
| 初始化新项目 | git init / git clone |
| 保存当前修改 | git add → git commit |
| 查看修改内容 | git status / git diff / git log |
| 创建新分支 | git checkout -b / git switch -c |
| 合并分支 | git merge / git rebase |
| 撤销错误提交 | git revert / git reset |
| 暂存当前工作 | git stash |
| 推送到远程 | git push / git pull |
初始化(2)
| 命令 | 难度 | ||
|---|---|---|---|
git init初始化一个新的 Git 仓库 | 基础 | git init my-project | |
git clone克隆远程仓库到本地 | 基础 | git clone https://github.com/user/repo.git |
基础操作(5)
| 命令 | 难度 | ||
|---|---|---|---|
git add将修改添加到暂存区 | 基础 | git add src/ 或 git add -A | |
git commit提交暂存区的修改 | 基础 | git commit -m "feat: add login feature" | |
git status查看工作区和暂存区状态 | 基础 | git status | |
git diff查看文件修改的具体内容 | 基础 | git diff 或 git diff --staged | |
git log查看提交历史 | 基础 | git log --oneline --graph --all |
分支管理(5)
| 命令 | 难度 | ||
|---|---|---|---|
git branch列出、创建或删除分支 | 基础 | git branch feature/login | |
git checkout -b创建并切换到新分支 | 基础 | git checkout -b feature/login | |
git switch切换到已有分支(现代写法) | 中级 | git switch feature/login | |
git merge将指定分支合并到当前分支 如遇冲突,解决后 git add + git commit 完成合并 | 中级 | git merge feature/login | |
git rebase将当前分支的提交移到目标分支顶端 不要对已推送的分支做 rebase | 高级 | git rebase main |
暂存操作(3)
| 命令 | 难度 | ||
|---|---|---|---|
git stash临时保存工作区的修改 | 中级 | git stash | |
git stash pop恢复最近一次 stashed 的修改并删除 stash | 中级 | git stash pop | |
git stash list列出所有 stashed 的保存点 | 中级 | git stash list |
撤销操作(4)
| 命令 | 难度 | ||
|---|---|---|---|
git reset --soft HEAD~1撤销最近一次提交,保留更改在暂存区 如果已推送,请用 git revert 替代 | 中级 | git reset --soft HEAD~1 | |
git reset --hard HEAD~1撤销最近一次提交,丢弃所有更改(危险) 🔴 此操作不可逆!丢弃的更改无法恢复 | 高级 | git reset --hard HEAD~1 | |
git revert通过创建新提交来撤销指定提交 | 中级 | git revert abc1234 | |
git restore撤销工作区的未暂存修改 | 基础 | git restore src/app.ts 或 git restore . |
远程操作(4)
| 命令 | 难度 | ||
|---|---|---|---|
git push将本地提交推送到远程仓库 | 基础 | git push origin main | |
git pull从远程拉取并合并 | 基础 | git pull origin main | |
git fetch从远程获取最新数据(不自动合并) | 中级 | git fetch origin | |
git remote -v查看远程仓库列表 | 基础 | git remote -v |
高级操作(3)
| 命令 | 难度 | ||
|---|---|---|---|
git tag列出或创建标签 | 中级 | git tag v1.0.0 | |
git cherry-pick将指定提交应用到当前分支 | 高级 | git cherry-pick abc1234 | |
git bisect二分查找引入 bug 的提交 | 高级 | git bisect start HEAD v1.0 |
本速查表数据整理自各工具官方文档。最后更新: 2026-07-15。