Skip to content

Git 常用命令

基础操作

bash
# 初始化仓库
git init

# 查看状态
git status

# 添加文件到暂存区
git add -A

# 提交
git commit -m "提交信息"

# 推送到远程
git push origin main

分支操作

bash
# 创建并切换分支
git checkout -b feature/new-feature

# 合并分支
git merge feature/new-feature

# 删除分支
git branch -d feature/new-feature

撤销操作

bash
# 撤销工作区修改
git checkout -- filename

# 撤销暂存
git reset HEAD filename

# 回退提交(保留修改)
git reset --soft HEAD~1

TIP

使用 git log --oneline -10 查看最近 10 条简洁提交记录。

用知识连接未来