1、回退代码到某个版本
场景:
提交顺序:commit-a --> commit-b --> commit-c
需要回到 commit-b 提交后的版本,丢弃后续的提交(commit-c)
解决步骤:
# 1.使用git log 查看历史提交
git log
# 2.找到需要回退版本的 commitId
如 0bea65aa
# 3.回退本地代码库
git reset --hard 0bea65aa
# 4.推送到远程
git push -f origin master
2、撤销某次merge、commit
场景:
提交顺序:commit-a --> commit-b --> commit-c
需要撤销 commit-b 提交,保留后续的提交(commit-c)
解决步骤:
# 1.使用git log 查看历史提交
git log
# 2.找到需要回退版本的 commitId
如 0bea65aa
# 3.撤销本次提交
git revert -m 1 0bea65aa
# 4.提交本次撤销
git commit -m 'revert'