干货:GIT常用命令

234 阅读1分钟

基本提交流程

查看修改文件 git status
提交文件到暂存区 git add .
提交文件到版本区 git commit -m "注释"
推送版本到远程分支 git push ( 强制推送 -f )

基本分支操作

查看本地分支 git branch
查看远程分支 git branch -a
创建本地分支 git branch 分支名
切换本地分支 git checkout 分支名
本地分支创建并切换 git checkout -b 分支名
删除本地分支 git branch -d 分支名
本地分支与远程分支建立关联 git push origin 分支名 : 分支名
本地分支创建并切换到指定版本 git checkout -b 分支名 版本号

基本回滚操作

拉取最新版本 git pull
查询版本日志 git log (拿到想回滚版本的sha)
回滚到指定版本 (不包含回滚版本后的git记录) git reset --hard sha

基本缓存操作

缓存下当前更改 git stash save "备注"
查看缓存列表 git stash list
恢复某一缓存并不删除缓存记录 git stash apply stash@{num}
恢复某一缓存删除缓存记录 git stash pop stash@{num}
清空缓存记录 git stash clear