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^
相关推荐
netyeaxi3 小时前
Git:git深入理解及常见问题
git
蹊黎5 小时前
Git 从入门到精通(二):创建本地仓库与三大核心区域
git
蹊黎7 小时前
Git 从入门到精通(一):初识 Git 与环境搭建
git
゛凌乱的记忆づ1 天前
好用的md文件编辑器——TyporaS与Typora
笔记·git·typora·markdown
এ慕ོ冬℘゜1 天前
Git 基础规范:小步提交、提交信息规范与常用命令
git·svn
忘了ʷºᵇₐ1 天前
Git学习笔记
笔记·git·学习
BIBI20492 天前
换 Git 托管平台怎么做?基于 TortoiseGit 的跨平台迁移教程
windows·git·tortoisegit·问题解决·版本控制·最佳实践
echome8882 天前
Git 日常救急:撤销提交、找回误删文件和解决冲突
git·版本控制
赵民勇2 天前
Git命令详解
git
不老刘3 天前
Antigravity 的 New Worktree 模式:给 AI 代理一个安全的“平行工位”
人工智能·git·ai编程·antigravity