设置全局身份信息
git config --global user.name "[name]"
git config --global user.email "[email]"在线Git速查表,汇总配置、初始化、提交、回退与分支等常用命令,支持分类速查和一键复制
设置全局身份信息
git config --global user.name "[name]"
git config --global user.email "[email]"查看全部配置
git config --list查看指定配置项
git config user.name创建 Git 仓库
git init克隆已有仓库
git clone [url]克隆指定分支
git clone -b [branch-name] [url]查看工作区状态
git status查看未暂存改动
git diff查看已暂存改动
git diff --staged查看最近一次提交详情
git show HEAD暂存所有改动
git add .暂存指定文件
git add [file]取消暂存指定文件
git restore --staged [file]丢弃工作区指定文件改动
git restore [file]提交暂存区内容
git commit -m "[commit message]"提交全部已跟踪改动
git commit -am "[commit message]"修改最近一次提交并保留原说明
git commit --amend --no-edit修改最近一次提交说明
git commit --amend -m "[commit message]"查看本地分支
git branch查看本地与远程分支
git branch -a创建新分支
git branch [branch-name]切换到指定分支
git switch [branch-name]创建并切换分支
git switch -c [branch-name]删除已合并分支
git branch -d [branch-name]强制删除分支
git branch -D [branch-name]重命名当前分支
git branch -m [new-branch-name]查看远程仓库
git remote -v添加远程仓库
git remote add origin [url]修改远程仓库地址
git remote set-url origin [url]删除远程仓库
git remote remove origin获取远程更新
git fetch origin拉取并合并指定分支
git pull origin [branch-name]拉取并使用 rebase
git pull --rebase origin [branch-name]推送到指定远程分支
git push origin [branch-name]推送并设置上游分支
git push -u origin [branch-name]安全地强制推送
git push --force-with-lease origin [branch-name]查看精简提交历史
git log --oneline --graph --decorate --all查看文件提交历史
git log -- [file]查看文件每行最后修改者
git blame [file]查看引用变动记录
git reflog创建完整仓库 bundle 文件
git bundle create repo.bundle --all校验 bundle 文件内容
git bundle verify repo.bundle从 bundle 克隆仓库
git clone repo.bundle [dir-name]从 bundle 拉取更新
git pull repo.bundle [branch-name]导出当前分支 ZIP 归档
git archive --format=zip --output=project.zip HEAD导出指定标签归档
git archive --format=tar.gz --output=release.tar.gz [tag-name]导出指定子目录
git archive --format=zip --output=folder.zip HEAD:[path]查看提交注释列表
git notes list为当前提交添加注释
git notes add -m "[note]"查看指定提交注释
git notes show [commit-hash]追加提交注释内容
git notes append -m "[note]" [commit-hash]删除指定提交注释
git notes remove [commit-hash]分析仓库历史结构
git filter-repo --analyze删除指定路径历史
git filter-repo --path [path] --invert-paths --force只保留指定路径历史
git filter-repo --path [path] --force批量替换历史中的敏感文本
git filter-repo --replace-text replacements.txt --force开始二分排查
git bisect start标记当前提交为有问题
git bisect bad标记当前提交为正常
git bisect good [commit-hash]重置并结束二分排查
git bisect reset检查仓库对象完整性
git fsck显示不可达对象
git fsck --unreachable检查并显示完整对象列表
git fsck --full清理并整理仓库对象
git gc --prune=now启用后台维护任务
git maintenance start执行自动维护
git maintenance run --auto注册当前仓库到维护计划
git maintenance register停止后台维护任务
git maintenance stop将当前分支变基到目标分支
git rebase [branch-name]继续处理中的变基
git rebase --continue跳过当前冲突提交
git rebase --skip中止当前变基
git rebase --abort用新对象替换旧对象引用
git replace [old-object] [new-object]查看全部替换规则
git replace -l编辑替换对象
git replace --edit [object-id]删除替换规则
git replace -d [object-id]启用 rerere 自动记录冲突解决
git config rerere.enabled true查看当前 rerere 状态
git rerere status查看 rerere 记录的冲突差异
git rerere diff忘记指定文件的冲突解决记录
git rerere forget [path]清空全部 rerere 记录
git rerere clear配置 Git Credential Manager
git config --global credential.helper manager-core配置内存凭据缓存
git config --global credential.helper cache写入凭据助手记录
git credential approve读取匹配的凭据
git credential fill删除匹配的凭据
git credential reject初始化稀疏检出
git sparse-checkout init --cone设置保留目录
git sparse-checkout set [path1] [path2]追加保留目录
git sparse-checkout add [path]关闭稀疏检出
git sparse-checkout disable保存当前改动到暂存栈
git stash push -m "[message]"查看暂存栈列表
git stash list恢复并删除最新暂存
git stash pop恢复指定暂存但保留记录
git stash apply stash@{0}删除指定暂存记录
git stash drop stash@{0}查看标签列表
git tag创建轻量标签
git tag [tag-name]创建附注标签
git tag -a [tag-name] -m "[tag message]"推送指定标签
git push origin [tag-name]推送全部标签
git push origin --tags指定自定义 hooks 目录
git config core.hooksPath .githooks查看当前 hooks 目录配置
git config core.hooksPath取消自定义 hooks 目录
git config --unset core.hooksPath让钩子脚本具备执行权限
chmod +x .githooks/pre-commit添加子模块
git submodule add [url] [path]初始化并拉取全部子模块
git submodule update --init --recursive更新子模块到远程最新提交
git submodule update --remote --recursive查看子模块状态
git submodule status查看工作树列表
git worktree list为新分支创建工作树
git worktree add ../[dir-name] -b [branch-name]移除工作树
git worktree remove ../[dir-name]清理失效工作树记录
git worktree prune撤销最近一次提交并保留改动
git reset HEAD~1软回退最近一次提交
git reset --soft HEAD~1撤销最近 N 次提交并保留改动
git reset HEAD~N撤销最近一次提交并丢弃改动
git reset HEAD~1 --hard回滚指定提交并生成新提交
git revert [commit-hash]将当前分支重置到远程状态
git fetch origin
git reset --hard origin/[branch-name]将本地 master 重命名为 main
git branch -m master main挑拣指定提交到当前分支
git cherry-pick [commit-hash]合并指定分支到当前分支
git merge [branch-name]删除未跟踪文件和目录
git clean -fd该工具整理了 Git 配置、状态检查、暂存、提交、分支、远程、同步、历史、仓库打包、归档导出、提交注释、历史清理、二分排查、仓库检查、仓库维护、变基、对象替换、冲突复用、凭据管理、稀疏检出、标签、钩子、子模块、工作树、暂存栈和回退修复等常用命令,适合在开发过程中快速查找并复制执行。
reset、amend、--hard 等高风险命令进行醒目标记。不会。页面只负责展示和复制命令,不会访问本地仓库或自动执行终端操作。
因为 amend、reset 和 --hard 可能改写历史或丢弃改动,执行前应确认影响范围。