Git 常用命令速查
配置git config --global user.name "Your Name"

设置用户名

配置git config --global user.email "you@example.com"

设置邮箱

配置git config --global init.default branch main

默认分支 main

初始化git init

创建新仓库

初始化git clone <url>

克隆远程仓库

提交git add .

暂存所有改动

提交git commit -m "msg"

提交暂存

提交git commit -am "msg"

提交已跟踪文件

分支git branch

查看分支

分支git checkout -b <name>

创建并切换

分支git merge <name>

合并分支

远程git remote add origin <url>

添加远程仓库

远程git push -u origin main

首次推送

远程git pull

拉取并合并

远程git fetch

只拉取不合并

撤销git reset --hard HEAD~1

撤销最后 1 次提交

撤销git checkout -- <file>

丢弃工作区修改

撤销git stash

暂存当前工作

撤销git stash pop

恢复暂存工作

查看git log --oneline

简洁日志

查看git status

查看状态

查看git diff

查看未暂存改动

查看git show <commit>

查看某次提交

标签git tag v1.0

创建标签

标签git push origin v1.0

推送标签