Git 常用命令
基础命令
初始化仓库
git init
克隆仓库
git clone <repository-url>
查看状态
git status
提交更改
添加文件
# 添加所有文件
git add .
# 添加指定文件
git add <file>
提交
git commit -m "提交信息"
分支管理
查看分支
git branch
创建分支
git branch <branch-name>
切换分支
git checkout <branch-name>
# 或者
git switch <branch-name>
合并分支
git merge <branch-name>
远程仓库
添加远程仓库
git remote add origin <url>
推送
git push -u origin main
拉取
git pull
实用技巧
撤销上次提交
git reset --soft HEAD~1
查看提交历史
git log --oneline