Git本地commit回退版本

素颜马尾好姑娘i 2023-06-06 13:29 142阅读 0赞

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

Git本地提交远程错误重置

问题

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

  1. $ git push origin master
  2. fatal: HttpRequestException encountered.
  3. ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
  4. Username for 'https://github.com': itbin@foxmail.com
  5. Counting objects: 22, done.
  6. Delta compression using up to 4 threads.
  7. Compressing objects: 100% (18/18), done.
  8. Writing objects: 100% (22/22), 1.83 MiB | 141.00 KiB/s, done.
  9. Total 22 (delta 2), reused 0 (delta 0)
  10. remote: Resolving deltas: 100% (2/2), completed with 1 local object.
  11. remote: error: GH001: Large files detected. You may want to try Git Large File Storage - https://git-lfs.github.com.
  12. remote: error: Trace: 2b24782bfa4d3fee2c4cc96cd60b53d2
  13. remote: error: See http://git.io/iEPt8g for more information.
  14. remote: error: File Java/Cron/Cron.resource/commit.json is 257.43 MB; this exceeds GitHub's file size limit of 100.00 MB
  15. To https://github.com/zhangruibin/YuWriterMdFile
  16. ! [remote rejected] master -> master (pre-receive hook declined)
  17. 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的在最上面,部分日志如下:

  1. $ git log
  2. commit eb13983f3b0c2cfba39ba2eeffb9001e3803086a (HEAD -> master)
  3. Author: zhrb <itbin@foxmail.com>
  4. Date: Sun Sep 29 08:58:43 2019 +0800
  5. java 源码学习1
  6. commit ad072b274daff241aa581285986f10734b4c8916
  7. Author: zhrb <itbin@foxmail.com>
  8. Date: Sun Sep 29 08:42:54 2019 +0800
  9. java 源码学习1
  10. commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (origin/master)
  11. Author: zhrb <itbin@foxmail.com>
  12. Date: Fri Sep 27 11:15:38 2019 +0800
  13. share
  14. commit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
  15. Author: zhrb <itbin@foxmail.com>
  16. Date: Fri Sep 27 09:59:37 2019 +0800
  17. thread

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

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

$ git reset d8191e0d0c3cbd1473b175804e2250d87036ba64

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

  1. $ git log
  2. commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (HEAD -> master, origin/master)
  3. Author: zhrb <itbin@foxmail.com>
  4. Date: Fri Sep 27 11:15:38 2019 +0800
  5. share
  6. commit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
  7. Author: zhrb <itbin@foxmail.com>
  8. Date: Fri Sep 27 09:59:37 2019 +0800
  9. thread

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

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

发表评论

表情:
评论列表 (有 0 条评论,142人围观)

还没有评论,来说两句吧...

相关阅读

    相关 git版本退

    工作中偶尔会遇到误把代码提交到正式环境分支需要撤回的情况,为了保证分支提交记录的干净,我们不能手动还原代码然后撤回,需要利用git机制进行撤回,这里记录下撤回方法 1.查询到