git pull 后发现此版本不是想要的版本,但pull后的版本迭代了N个版本
如何恢复到本分支的原来版本呢
一:git reflog master (查看本地master分支历史变动纪录)
[develop]$ sudo git reflog master
ce751d1 master@{0}: pull origin master: Merge made by the 'recursive' strategy.
ee23214 master@{1}: commit (merge): 1
152ce90 master@{2}: commit: 1
771ac6b master@{3}: pull origin master: Fast-forward
29539fd master@{4}: pull origin master: Fast-forward
7a65fe5 master@{5}: pull origin master: Fast-forward
1715f9f master@{6}: pull origin master: Fast-forward
二:对比提交日志找到需要后滚到的编号
提交记录的编号需要细心核对别取错了
771ac6b master@{3}: pull origin master: Fast-forward
这里的771ac6b就是编号(COMMIT_ID)
三:执行回滚
git reset --hard <COMMIT_ID> (恢复到之前位置)
例如
git reset --hard 771ac6b