git版本回退

代码推送到远程仓库之后想回退并且不保留任何历史记录:

  1. 查看版本号信息git log
bash 复制代码
git log
commit version_example1  (HEAD -> dev, origin/dev, origin/HEAD)
Author: xxx <email>
Date: xxx
   XXX注释
   
commit version_example2
Author: xxx <email>
Date: xxx
   XXX注释
  1. 回退git reset --hard 目标版本号
bash 复制代码
git reset --hard version_example2
  1. 推送到远程仓库git push -f
bash 复制代码
git push -f

注:如果是保护分支,需要先解除保护,推送成功之后再加保护!


由于没有及时回退,导致开发组内其他同事代码更新到了之前的变更,这时候该同事执行git pull会报错:

bash 复制代码
s glt pull
hint: Pulling without specifying how to reconcile divergent branches is
hint: discouraged. You can squelch this message by running one of the following
hint: commands sometime before your next pull:
hint:
hint:    git config pull.rebase false  # merge (the default'strategy)
hint:    git config pull.rebase true   # rebase
hint:    git config pull.ff only       # fast-forward only
hint:
hint: You can replace "git config" with "git config --global" to set a default
hint: preference for all repositories, You can also pass --rebase, --no-rebase
hint: or --ff-only on the command line to override the configured default per
hint: invocation.
Already up to date.
bash 复制代码
$ git status
on brancn dev
Your branch is ahead of 'origin/dev' by l commit.
(use "git push" to publish your local commits)

注意保存好开发变更的代码

将该变更撤销即可:

bash 复制代码
git reset --hard HEAD^
相关推荐
梅梅绵绵冰8 小时前
Git分支管理
git
ys~~9 小时前
git学习
git·vscode·python·深度学习·学习·nlp·github
Rysxt_13 小时前
IDEA中Git隐藏更改(Stash)功能详解教程
数据库·git·intellij-idea·stash
Mr-Apple14 小时前
记录一次git commit --amend的误操作
大数据·git·elasticsearch
UVM_ERROR16 小时前
Git仓库损坏(Segmentation fault)修复实战:虚拟机环境下UVM项目救援指南
笔记·git·vscode·github·芯片
j_xxx404_17 小时前
Linux:版本控制器Git(第一章)|历史|理解Git|相关git操作|提交冲突解决
linux·运维·git·ai
牛奔17 小时前
git本地提交后,解决push被拒绝 error: failed to push some refs to
大数据·git·elasticsearch·搜索引擎·全文检索
少年姜太公1 天前
什么?还不知道git cherry pick?
前端·javascript·git
MatrixOrigin1 天前
在数据库里玩“平行宇宙”:MatrixOne Data Branch 让数据也拥有Git 的分支/合并/对比/回滚(含跨集群同步)
git·sql·数据分析
VcB之殇1 天前
git常用操作合集
前端·git