Git 速查手册

快速查找常用 Git 命令和用法

配置

git config --global user.name "[name]"

设置用户名

git config --global user.email "[email]"

设置邮箱

git config --list

查看配置

创建与克隆

git init

初始化本地仓库

git clone [url]

克隆远程仓库

基本操作

git status

查看状态

git add [file]

添加文件到暂存区

git add .

添加所有文件到暂存区

git commit -m "[message]"

提交更改

git log

查看提交历史

git diff

查看未暂存的更改

分支管理

git branch

列出所有分支

git branch [branch-name]

创建新分支

git checkout [branch-name]

切换分支

git checkout -b [branch-name]

创建并切换到新分支

git merge [branch]

合并指定分支到当前分支

git branch -d [branch-name]

删除分支

远程仓库

git remote add [name] [url]

添加远程仓库

git remote -v

查看远程仓库

git push [remote] [branch]

推送到远程仓库

git pull [remote] [branch]

从远程仓库拉取

git fetch [remote]

从远程仓库获取

撤销操作

git reset [file]

取消暂存文件

git reset --hard [commit]

重置到指定提交

git revert [commit]

回退指定提交

git checkout -- [file]

丢弃工作区修改

需要更详细的说明?

查看我们的完整教程了解每个命令的详细用法

浏览教程