Git本地commit回退版本

编程入门 行业动态 更新时间:2024-10-19 17:26:49

Git本地commit回退<a href=https://www.elefans.com/category/jswz/34/1771446.html style=版本"/>

Git本地commit回退版本

欢迎关注微信公众号: 程序员小圈圈
原文首发于: www.zhangruibin
本文出自于: RebornChang的博客
转载请标明出处^_^

Git本地提交远程错误重置

问题

今天笔者照例要把几个MD文件推送到GitHub库,但是经过add 和commit的再push到远程的时候出错了,看下面的错误信息:

$ git push origin master
fatal: HttpRequestException encountered.▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for '': itbin@foxmail
Counting objects: 22, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (22/22), 1.83 MiB | 141.00 KiB/s, done.
Total 22 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 1 local object.
remote: error: GH001: Large files detected. You may want to try Git Large File Storage - .
remote: error: Trace: 2b24782bfa4d3fee2c4cc96cd60b53d2
remote: error: See  for more information.
remote: error: File Java/Cron/Cron.resource/commit.json is 257.43 MB; this exceeds GitHub's file size limit of 100.00 MB
To ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''

可以看到,GitHub的单文件大小不能超过100M,我commit的文件有一个两百多M的,所以失败了,那咋办,本地已经commit了,那就只能将本地的commit回滚了。

解决办法

使用Git log 及git reset commitId来实现。

首先执行git log 命令,来查看log日志,日志是按照时间倒叙的,最后commit的在最上面,部分日志如下:

$  git log
commit eb13983f3b0c2cfba39ba2eeffb9001e3803086a (HEAD -> master)
Author: zhrb <itbin@foxmail>
Date:   Sun Sep 29 08:58:43 2019 +0800java 源码学习1commit ad072b274daff241aa581285986f10734b4c8916
Author: zhrb <itbin@foxmail>
Date:   Sun Sep 29 08:42:54 2019 +0800java 源码学习1commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (origin/master)
Author: zhrb <itbin@foxmail>
Date:   Fri Sep 27 11:15:38 2019 +0800sharecommit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
Author: zhrb <itbin@foxmail>
Date:   Fri Sep 27 09:59:37 2019 +0800thread

可以看到远端仓库的commitId 为:d8191e0d0c3cbd1473b175804e2250d87036ba64

此时我们执行下面的命令:

$ git reset d8191e0d0c3cbd1473b175804e2250d87036ba64

然后再执行git log可以看到,已经重置到跟远端仓库一致的版本了。

$ git log
commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (HEAD -> master, origin/master)
Author: zhrb <itbin@foxmail>
Date:   Fri Sep 27 11:15:38 2019 +0800sharecommit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
Author: zhrb <itbin@foxmail>
Date:   Fri Sep 27 09:59:37 2019 +0800thread

本地commit 回退了版本之后,笔者处理掉那个两百多M的文件再重新commit,就跟之前的commit流程一样了,可以顺利的提交到Github了。

,博主的微信公众号
程序员小圈圈’开始持续更新了哟~~
识别二维码或者直接搜索名字 ‘程序员小圈圈’ 即可关注本公众号哟~~
不只是有技术哟~~
还有很多的学习娱乐资源免费下载哦~~
还可以学下教育知识以及消遣娱乐哟~~
求关注哟~~

更多推荐

Git本地commit回退版本

本文发布于:2024-03-10 08:24:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1727466.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   Git   commit

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!