当前位置: 首页 > news >正文

git revert 撤销之前的提交

git revert 用来撤销之前的提交,它会生成一个新的 commit id 。

输入 git revert --help 可以看到帮忙信息。

git revert commitID

不编辑新的 commit 说明

git log 找到需要撤销的 commitID ,

然后执行 git revert commitID ,会提示如下,
在这里插入图片描述
如果不需要编辑 commit 说明,直接 Ctrl + X 退出即可。

git log 查看,本地已有一条新的提交,并且自带一条提交说明,
在这里插入图片描述
git push ,完成。

编辑新的 commit 说明

git log 找到需要撤销的 commitID ,

然后执行 git revert commitID ,会提示如下,
在这里插入图片描述
输入需要编辑的信息,
建议保留原有的这些信息,方便以后查找

    Revert "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"This reverts commit xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1d4f9122f9dc3946a73bad.

如,在这些原有信息前加一行,
在这里插入图片描述
编辑完成后 Ctrl + X 退出,会提示是否保存,输入 Y 保存,
在这里插入图片描述
git log 查看,本地已有一条新的提交,并且带有我添加的提交说明,
在这里插入图片描述

git push ,完成。

git revert -n commitID

git revert commitID 会直接进入编辑器,看不到状态,加上 -n 参数可以看到。

       -n, --no-commitUsually the command automatically creates some commits with commit log messages stating which commits were reverted. This flagapplies the changes necessary to revert the named commits to your working tree and the index, but does not make the commits. Inaddition, when this option is used, your index does not have to match the HEAD commit. The revert is done against the beginning stateof your index.This is useful when reverting more than one commits' effect to your index in a row.

执行 git revert -n commitID 后,git status 查看状态,此时处于 已 git add 未 git commit 的状态。
在这里插入图片描述
如果不想继续执行了,用 git revert --abort 放弃本次修改。

继续执行的话,就用 git revert --continue ,后续步骤和前文的 【git revert commitID 章节】 一致。

git revert HEAD~3

帮助信息说明,

git revert HEAD~3Revert the changes specified by the fourth last commit in HEAD and create a new commit with the reverted changes.

执行后提示如下,
在这里插入图片描述

git log 查看,本地生成一条新的提交。

注意,它 revert 的是第4条提交!!!
在这里插入图片描述

http://www.lryc.cn/news/176767.html

相关文章:

  • rk3568环境配置和推理报错: RKNN_ERR_MALLOC_FAIL
  • 网络工程师基础笔记(一)
  • Postman应用——Headers请求头设置
  • 人人都是项目经理-项目管理概述(一)
  • 浅谈基于物联网的医院消防安全管理
  • 户用储能争斗:华宝新能“稳”、正浩科技“快”、安克创新“急”
  • 【面试篇】集合相关高频面试题
  • RT Preempt linux学习笔记
  • JavaScript 基础第四天笔记
  • Unity 2021.x及以下全版本Crack
  • 基于知识蒸馏的夜间低照度图像增强及目标检测
  • 4、ARM异常处理
  • 【Element-UI】CUD(增删改)及form 表单验证(附源码)
  • 2024年高新技术企业认定标准
  • 励磁工作原理
  • 【JAVA】获取当前项目的classpath路径
  • Sulfo CY3-DBCO蛋白质标记实验-星戈瑞
  • 【不规范bug注意】2023.9.26
  • it端到端运维监控
  • Vue3根组件设置Transition失效的问题
  • 2023-2024年最新大数据学习路线
  • Cocos Creator3.8 实战问题(三)去除scrollview背景色和label 对齐方式设置无效问题
  • 以太坊代币标准ERC20、ERC165、ERC721
  • spring cloud gateway谓词工厂 Predicate Factory
  • 美丽塔O(n)解法单调栈
  • ​的PDF文件压缩软件PDF Squeezer mac中文版​软件特点
  • JS Ajax 封装
  • 观测云产品更新 | 优化日志数据转发、索引绑定、基础设施自定义等
  • trio ValueEvent
  • js 新学一招,点击出现弹框,点击其他地方关闭弹框