Git本地commit回退版本

歡迎關注微信公衆號:程序員小圈圈
原文首發於:www.zhangruibin.com
本文出自於:RebornChang的博客
轉載請標明出處^_^

Git本地提交遠程錯誤重置

問題

今天筆者照例要把幾個MD文件推送到GitHub庫,但是經過add 和commit的再push到遠程的時候出錯了,看下面的錯誤信息:

$ git push origin master
fatal: HttpRequestException encountered.
   ▒▒▒▒▒▒▒▒ʱ▒▒▒▒
Username for 'https://github.com': [email protected]
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 <[email protected]>
Date:   Sun Sep 29 08:58:43 2019 +0800

    java 源碼學習1

commit ad072b274daff241aa581285986f10734b4c8916
Author: zhrb <[email protected]>
Date:   Sun Sep 29 08:42:54 2019 +0800

    java 源碼學習1

commit d8191e0d0c3cbd1473b175804e2250d87036ba64 (origin/master)
Author: zhrb <[email protected]>
Date:   Fri Sep 27 11:15:38 2019 +0800

    share

commit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
Author: zhrb <[email protected]>
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 <[email protected]>
Date:   Fri Sep 27 11:15:38 2019 +0800

    share

commit 695c8ebcc3a6c7089c257fc917e3d9fd19859fa6
Author: zhrb <[email protected]>
Date:   Fri Sep 27 09:59:37 2019 +0800

    thread

本地commit 回退了版本之後,筆者處理掉那個兩百多M的文件再重新commit,就跟之前的commit流程一樣了,可以順利的提交到Github了。

,博主的微信公衆號
程序員小圈圈’開始持續更新了喲~~
識別二維碼或者直接搜索名字 ‘程序員小圈圈’ 即可關注本公衆號喲~~
不只是有技術喲~~
還有很多的學習娛樂資源免費下載哦~~
還可以學下教育知識以及消遣娛樂喲~~
求關注喲~~

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章