Files
2026-11-05 14:35:04 +08:00

1.5 KiB

Git 常用命令

开发中最常用的命令,简洁实用


日常操作

场景 命令
拉取代码 git pull
查看状态 git status
添加修改 git add .
提交 git commit -m "说明"
推送 git push

分支操作

场景 命令
查看分支 git branch -a
创建分支 git checkout -b <分支名>
切换分支 git checkout <分支名>
合并分支 git merge <分支名>
删除分支 git branch -d <分支名>

撤销操作

场景 命令
撤销修改 git restore <文件>
取消add git restore --staged <文件>
回退上次提交 git reset --soft HEAD~1
暂存工作 git stash
恢复暂存 git stash pop

查看信息

场景 命令
提交历史 git log --oneline
最近5条 git log -5 --oneline
文件修改历史 git log -p <文件>
查看差异 git diff
指定提交者 查看提交记录 git log --author=lihai --all

一句话流程

每天开始:git pull
完成任务:git add . && git commit -m "说明" && git push
切换任务:git stash && git checkout <分支>

💡 不记得命令用 git help 查看