今天用git提交代码时忘记切换分支,直接在主分支master上commit了,还没有push (为时不晚)。
首先查看git reset --hard HEAD^
当前版本
$ git reset --hard HEAD^
HEAD is now at 6146f2b 添加支付模块
接下来查看一下日志
git relog
$ git reflog
67541f2(origin/qiang, qiang) HEAD@{5}: commit: 添加支付模块
21998f2 HEAD@{6}: checkout: moving from master to qiang
21998f2 HEAD@{7}: checkout: moving from qiang to master
21998f2 HEAD@{8}: checkout: moving from master to qiang
21998f2 HEAD@{9}: merge qiang: Fast-forward
e851704 HEAD@{10}: checkout: moving from qiang to master
21998f2 HEAD@{11}: commit: 添加运营设置模块
e851704 HEAD@{12}: checkout: moving from master to qiang
e851704 HEAD@{13}: merge qiang: Fast-forward
9875a67 HEAD@{14}: checkout: moving from qiang to master
e851704 HEAD@{15}: commit: 添加多图上传插件
052d724 HEAD@{16}: commit: 添加权限管理
9875a67 HEAD@{17}: merge master: Fast-forward
5702520 HEAD@{18}: checkout: moving from master to qiang
9875a67 HEAD@{19}: commit: 修改配置文件
2337d7c HEAD@{20}: commit: 配置文件
6961f4b HEAD@{21}: commit: 添加配置文件
ec6b90e HEAD@{22}: commit: 添加index.php
02d496a HEAD@{23}: commit: 添加vendor
5702520 HEAD@{24}: merge qiang: Fast-forward
3875964 HEAD@{25}: checkout: moving from qiang to master
5702520 HEAD@{26}: commit: 添加管理员模块
5ab3c57 HEAD@{27}: commit: 修改yii.bat
3875964 HEAD@{28}: merge master: Fast-forward
6ca0a96 (origin/dev) HEAD@{29}: checkout: moving from master to qiang
3875964 HEAD@{30}: checkout: moving from qiang to master
6ca0a96 (origin/dev) HEAD@{31}: checkout: moving from master to qiang
3875964 HEAD@{32}: commit: 添加数据库文件
e70e3dc HEAD@{33}: commit: 修改首页
5443cf5 HEAD@{34}: commit: 添加项目文件
6ca0a96 (origin/dev) HEAD@{35}: commit (initial): 添加说明文档
#我这里选择一次最近的即可
git reset --haed e851704