有的时候我们提交了代码,或拉去了代码后发现有些问题需要代码回退。
本地版本回退。先查询提交记录。
1:git reflog
“e0bdefc” 类似于这样的字符串就是每次提交的版本
2:版本回退,操作 git reset --hard e0bdefc
或者你想将最近三次的提交回滚,git reset --hard HEAD~3
3:如果想远程版本回退
原理:先将本地分支退回到某个commit,删除远程分支,再重新push本地分支
1,git checkout the_branch
2,git pull
3,git branch the_branch_backup //备份一下这个分支当前的情况
4,git reset –hard the_commit_id //把the_branch本地回滚到the_commit_id
5,git push origin :the_branch //删除远程 the_branch
6,git push origin the_branch //用回滚后的本地分支重新建立远程分支
7,git push origin :the_branch_backup //如果前面都成功了,删除这个备份分支