Git 命令生成器
git init初始化新仓库
git clone <url>克隆远程仓库
git add .添加所有更改到暂存区
git add <file>添加指定文件到暂存区
git commit -m "message"提交暂存区更改
git commit --amend修改上次提交
git push origin <branch>推送到远程分支
git push -u origin <branch>推送并设置上游分支
git pull拉取远程更新并合并
git fetch获取远程更新(不合并)
git branch列出本地分支
git branch <name>创建新分支
git branch -d <name>删除本地分支
git checkout <branch>切换到指定分支
git checkout -b <branch>创建并切换到新分支
git switch <branch>切换分支(推荐)
git switch -c <branch>创建并切换(推荐)
git merge <branch>合并指定分支到当前分支
git merge --no-ff <branch>禁用快进合并
git rebase <branch>变基到指定分支
git rebase -i HEAD~<n>交互式变基最近 n 次提交
git stash暂存当前更改
git stash pop恢复暂存的更改
git stash list列出所有暂存
git log --oneline简洁查看提交历史
git log --graph --oneline图形化查看分支历史
git diff查看未暂存的更改
git diff --staged查看已暂存的更改
git status查看仓库状态
git reset HEAD~1撤销上次提交(保留更改)
git reset --hard HEAD~1撤销上次提交(丢弃更改)
git revert <commit>反转指定提交
git checkout -- <file>丢弃文件更改
git cherry-pick <commit>摘取指定提交
git tag <name>创建标签
git blame <file>查看文件每行最后修改
git bisect start开始二分查找 bug
• 常用 Git 命令速查 • 点击复制命令
常见问题