Git 命令速查

Git 常用命令速查表:初始化、提交、分支、合并、回滚等 40 条高频命令。

纯浏览器本地运行,数据不上传服务器

命令说明
git init初始化仓库
git clone <url>克隆远程仓库
git status查看工作区状态
git add <file>暂存文件(. 全部)
git commit -m "msg"提交暂存内容
git commit -am "msg"暂存并提交(已跟踪文件)
git push推送到远程
git pull拉取并合并远程
git fetch拉取远程但不合并
git branch列出本地分支
git branch <name>创建分支
git checkout <branch>切换分支
git checkout -b <name>创建并切换分支
git switch <branch>切换分支(新写法)
git merge <branch>合并分支到当前
git log查看提交历史
git log --oneline单行提交历史
git log --graph图形化历史
git diff查看未暂存改动
git diff --staged查看已暂存改动
git show <commit>查看某次提交
git stash暂存工作区改动
git stash pop恢复暂存改动
git reset --soft HEAD~1撤销提交保留改动
git reset --hard HEAD~1撤销提交丢弃改动
git revert <commit>反向提交(安全撤销)
git rm <file>删除文件并暂存
git mv <old> <new>重命名文件
git remote -v查看远程地址
git remote add <name> <url>添加远程
git tag <name>打标签
git tag -l列出标签
git config --global user.name "x"设置用户名
git config --global user.email "x"设置邮箱
git config --list查看配置
git rebase <branch>变基
git cherry-pick <commit>挑选提交
git bisect start二分定位问题
git blame <file>查看每行来源
git gc垃圾回收优化

使用说明

  1. 速查 Git 高频命令:提交、分支、合并、回滚、远端操作。
  2. 搜索支持按命令名或用途过滤。
  3. 开发日常记不住的命令在这里查。

常见问题

reset 和 revert 有什么区别?
reset 回退历史(改历史,慎用于已推送);revert 生成反向提交(安全,保留历史)。
怎么撤销已推送的提交?
优先 git revert(不重写历史);本地未推送可用 reset --hard。
反馈