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 等撤销和暂存命令
支持搜索命令或中文描述