免费Git 命令生成器

常用 Git 命令速查和复制

git
命令
版本控制
分支
command
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 命令速查 • 点击复制命令

相关工具

常见问题