Git 常用命令笔记
更新于 2026-07-09
Git 常用命令笔记
记录 git status、add、commit、push、pull、restore、reset、远程仓库配置等。
日常操作
# 查看状态
git status
# 添加文件
git add filename
git add .
# 提交
git commit -m "message"
# 推送到远程
git push origin master
# 拉取最新
git pull origin master
撤销与回退
# 撤销工作区修改
git restore filename
# 取消暂存
git restore --staged filename
# 回退到某个提交
git reset --hard commit_hash
git reset --soft commit_hash
远程仓库
# 添加远程仓库
git remote add origin url
# 查看远程
git remote -v
# 克隆仓库
git clone url
查看历史
git log --oneline --graph
git log -p filename
git diff