Git本地commit回退版本

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

Git本地提交远程错误重置

问题

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

$ git push origin master
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': itbin@foxmail.com
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 - https://git-lfs.github.com.
remote: error: Trace: 2b24782bfa4d3fee2c4cc96cd60b53d2
remote: error: See http://git.io/iEPt8g 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 https://github.com/zhangruibin/YuWriterMdFile
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://github.com/zhangruibin/YuWriterMdFile'

可以看到,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.com>
Date:   Sun Sep 29 08:58:43 2019 +0800

    java 源码学习1

commit ad072b274daff241aa581285986f10734b4c8916
Author: zhrb <itbin@foxmail.com>
Date:   Sun Sep 29 08:42:54 2019 +0800

    java 源码学习1

commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (origin/master)
Author: zhrb <itbin@foxmail.com>
Date:   Fri Sep 27 11:15:38 2019 +0800

    share

commit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
Author: zhrb <itbin@foxmail.com>
Date:   Fri Sep 27 09:59:37 2019 +0800

    thread

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

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

$ git reset d8191e0d0c3cbd1473b175804e2250d87036ba64

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

$ git log
commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (HEAD -> master, origin/master)
Author: zhrb <itbin@foxmail.com>
Date:   Fri Sep 27 11:15:38 2019 +0800

    share

commit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
Author: zhrb <itbin@foxmail.com>
Date:   Fri Sep 27 09:59:37 2019 +0800

    thread

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

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值