$ git logcommit a44822002522f2ab1e3a5e2a1cec00a7d3d02185 (HEAD -> master, origin/master, origin/HEAD)Author: hanchao5272 <热门标签热门文章- 1数据库开发-Mysql03
- 2无人机刚体运动学方程_无人机运动学方程
- 3android studio修改项目名,模块名,包名_androidstudio rename directory
- 4Hive超详细安装_hive安装
- 5renesas vin的解析_vin通道
- 6【MySQL】索引(上)
- 7Docker 快速入门(一文上手 Docker)_docker快速入门镜像基本操作心得
- 8【华为OD题库C卷-001】山脉的个数
- 92024年最全手把手教你用python一键抢12306火车票(附代码)_pthon 抢火车票_python自动抢火车票
- 10软件项目开发各阶段文档全套模板(规格说明书+详细设计+测试计划+验收报告)_软件项目描述文档
当前位置: article > 正文 git撤销已经push的代码_2git 如何撤回已push的代码1.8万
作者:很楠不爱3 | 2024-06-17 02:22:38 赞
踩
2git 如何撤回已push的代码1.8万
1.撤销提交信息
首先,通过git log
查看提交信息,以便获取需要回退至的版本号:
- <span style="color:#000000"><code class="language-shell">$ git log
- commit a44822002522f2ab1e3a5e2a1cec00a7d3d02185 (HEAD -> master, origin/master, origin/HEAD)
- Author: hanchao5272 <<span style="color:#006666 !important">89298141</span>@qq<span style="color:#009900 !important">.com</span>>
- Date: Sun Mar <span style="color:#006666 !important">4</span> <span style="color:#006666 !important">11</span>:<span style="color:#006666 !important">14</span>:<span style="color:#006666 !important">55</span> <span style="color:#006666 !important">2018</span> +<span style="color:#006666 !important">0800</span>
-
- CSDN-java反射<span style="color:#006666 !important">06</span>-成员变量Field-代码优化
-
- commit aa909cff2239536df14820fe086d96305b24e9f1
- Author: hanchao5272 <<span style="color:#006666 !important">89298141</span>@qq<span style="color:#009900 !important">.com</span>>
- Date: Sat Mar <span style="color:#006666 !important">3</span> <span style="color:#006666 !important">23</span>:<span style="color:#006666 !important">43</span>:<span style="color:#006666 !important">03</span> <span style="color:#006666 !important">2018</span> +<span style="color:#006666 !important">0800</span>
-
- CSDN-java反射-修饰符-代码优化
- </code></span>
- 我们需要撤销CSDN-java反射06-成员变量Field-代码优化这次提交,所以需要回退至的版本是CSDN-java反射-修饰符-代码优化,即需要回退至的版本号是:aa909cff2239536df14820fe086d96305b24e9f1。
然后,通过git reset –soft <版本号>重置至指定版本的提交,达到撤销提交的目的:
- 参数soft指的是:保留当前工作区,以便重新提交
还可以选择参数hard,会撤销相应工作区的修改,一定要谨慎使用
然后,通过git log
确认是否成功撤销:
- <span style="color:#000000"><code class="language-shell">$ git <span style="color:#000088 !important">log</span>
- commit aa909cff2239536df14820fe086d96305b24e9f1 (HEAD <span style="color:#4f4f4f !important">-> </span>master)
- Author: hanchao5272 <span style="color:#4f4f4f !important"><</span><span style="color:#006666 !important">89298141</span>@qq<span style="color:#4f4f4f !important">.</span>com<span style="color:#4f4f4f !important">></span>
- <span style="color:#4f4f4f !important">Date</span>: Sat Mar <span style="color:#006666 !important">3</span> <span style="color:#006666 !important">23</span>:<span style="color:#006666 !important">43</span>:<span style="color:#006666 !important">03</span> <span style="color:#006666 !important">2018</span> <span style="color:#4f4f4f !important">+</span><span style="color:#006666 !important">0800</span>
-
- CSDN<span style="color:#98c379">-java</span>反射<span style="color:#4f4f4f !important">-</span>修饰符<span style="color:#4f4f4f !important">-</span>代码优化
- </code></span>
已经成功撤销。
2.撤销
通过git push origin master –force强制提交当前版本号,master是什么分支就写什么分支这里以master实力以达到撤销版本号的目的:
- <span style="color:#000000"><code class="language-shell">$ git <span style="color:#000088 !important">push</span> origin master --force
- Total <span style="color:#006666 !important">0</span> (delta <span style="color:#006666 !important">0</span>), reused <span style="color:#006666 !important">0</span> (delta <span style="color:#006666 !important">0</span>)
- To github<span style="color:#009900 !important">.com</span>:hanchao5272/myreflect<span style="color:#009900 !important">.git</span>
- + a448220..<span style="color:#009900 !important">.aa</span>909cf master -> master (forced update)
- </code></span>
必须添加参数force进行强制提交,否则会提交失败,并报错:
报错原因:本地项目版本号低于远端仓库版本号。
3.修改代码,重新提交和推送
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/729274推荐阅读
相关标签Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。