{"id":2214,"date":"2022-05-27T20:17:43","date_gmt":"2022-05-27T12:17:43","guid":{"rendered":"https:\/\/www.techcoil.com\/blog\/?p=2214"},"modified":"2022-05-27T15:18:15","modified_gmt":"2022-05-27T07:18:15","slug":"how-i-repaired-one-of-my-corrupted-git-repository-on-gogs-git-server","status":"publish","type":"post","link":"https:\/\/www.techcoil.com\/blog\/how-i-repaired-one-of-my-corrupted-git-repository-on-gogs-git-server\/","title":{"rendered":"How I repaired one of my corrupted git repository on gogs git server"},"content":{"rendered":"<p>While trying to commit my codes to my <a href=\"https:\/\/www.techcoil.com\/blog\/setting-up-your-own-raspberry-pi-3-git-server-with-go-git-service-gogs-and-raspbian-stretch-lite\/\" rel=\"noopener\" target=\"_blank\">Raspberry Pi gogs git server<\/a>, I got a rejection:<\/p>\n<pre>\r\n ! [remote rejected] master -> master (missing necessary objects)\r\nerror: failed to push some refs to 'http:\/\/192.168.1.115:3000\/org\/a-project.git'\r\n<\/pre>\n<p>In addition to that, I got a HTTP 500 when I try to view the repository details page via the dashboard.<\/p>\n<p>Since I can view my other repositories on my gogs git server, something must be wrong with a-project.git.<\/p>\n<p>Given that, here are the steps that I took to rectify the issue.<\/p>\n<h2>Checking the logs on my gogs git server to find the root of the problem<\/h2>\n<p>Firstly, I went ahead to check the log file on my gogs git server. In order to do so, I went into the log folder and view the most recent log:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/opt\/gogs\/log\/\r\nsudo cat gogs.log\r\n<\/pre>\n<p>Given that, I was able to find a log status suggesting that the repository was corrupted:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\n2022\/05\/26 19:47:46 &#x5B;...ules\/context\/repo.go:384 func1()] &#x5B;E] CommitsCount: exit status 128 - error: inflate: data stream error (invalid code -- missing end-of-block)\r\nfatal: loose object eeba0893914f4e4c8f16da67fd4b1acd9e9041a3 (stored in .\/objects\/ee\/ba0893914f4e4c8f16da67fd4b1acd9e9041a3) is corrupt\r\n<\/pre>\n<p>When I saw such a message, I knew that one of the files in <code>a-project.git\/objects<\/code> is corrupted.<\/p>\n<h2>Copying a healthy git repository over to the gogs server<\/h2>\n<p>After getting the root to the problem, the next step is to solve it.<\/p>\n<h3>Locating the same objects folder on my local git repository<\/h3>\n<p>Since I am the sole developer, I have a healthy git repo on my development machine. In order to find the objects folder to copy over to my gogs git server, I simply change directory into the <code>.git<\/code> folder where the root of the source codes of my project sits.<\/p>\n<h3>Locating the objects folder on my gogs git server<\/h3>\n<p>Next, I proceeded to locate the objects directory on my gogs git server. Since gogs git server saves the repository in the home directory, I am able to find my objects folder in <code>\/home\/gogs\/gogs-repositories\/org\/a-project.git<\/code><\/p>\n<h3>Transferring the objects directory from my development machine to my gogs git server<\/h3>\n<p>Once I have an idea of where the objects directory resides locally and remotely, I proceeded to run the following commands on my development machine to get the objects folder to the home directory of my admin user on the git server:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/folder\/to\/project-source\/.git\r\nscp -r objects adminuser@192.168.1.115:\/home\/adminuser\/\r\n<\/pre>\n<p>When everything is transferred across, I sshed into my gogs server:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nssh adminuser@192.168.1.115\r\n<\/pre>\n<p>After getting into my gogs server as the admin user, I make a backup of the objects folder with the corrupted record:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\ncd \/home\/gogs\/gogs-repositories\/org\/a-project.git\r\n# Make a backup first just in case\r\nsudo mv objects objects-bak\r\nsudo mv \/home\/adminuser\/objects .\/\r\n<\/pre>\n<p>Given that, my git repository on my gogs server is no longer corrupted. In addition to that, whatever I had committed to my local repository were also transferred over to the remote repository.<\/p>\n\n      <ul id=\"social-sharing-buttons-list\">\n        <li class=\"facebook\">\n          <a href=\"https:\/\/www.facebook.com\/sharer\/sharer.php?u=https%3A%2F%2Fwp.me%2Fp245TQ-zI\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n            <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Facebook.png\" alt=\"Facebook icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"twitter\">\n          <a href=\"https:\/\/twitter.com\/intent\/tweet?text=&url=https%3A%2F%2Fwp.me%2Fp245TQ-zI&via=Techcoil_com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Twitter.png\" alt=\"Twitter icon\"> Tweet\n          <\/a>\n        <\/li>\n        <li class=\"linkedin\">\n          <a href=\"https:\/\/www.linkedin.com\/shareArticle?mini=1&title=&url=https%3A%2F%2Fwp.me%2Fp245TQ-zI&source=https:\/\/www.techcoil.com\" target=\"_blank\" role=\"button\" rel=\"nofollow\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/linkedin.png\" alt=\"Linkedin icon\"> Share\n          <\/a>\n        <\/li>\n        <li class=\"pinterest\">\n          <a href=\"https:\/\/pinterest.com\/pin\/create\/button\/?url=https%3A%2F%2Fwww.techcoil.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2214&description=\" class=\"pin-it-button\" target=\"_blank\" role=\"button\" rel=\"nofollow\" count-layout=\"horizontal\">\n          <img decoding=\"async\" src=\"\/ph\/img\/3rd-party\/social-icons\/Pinterest.png\" alt=\"Pinterest icon\"> Save\n          <\/a>\n        <\/li>\n      <\/ul>\n    ","protected":false},"excerpt":{"rendered":"<p>While trying to commit my codes to my <a href=\"https:\/\/www.techcoil.com\/blog\/setting-up-your-own-raspberry-pi-3-git-server-with-go-git-service-gogs-and-raspbian-stretch-lite\/\" rel=\"noopener\" target=\"_blank\">Raspberry Pi gogs git server<\/a>, I got a rejection:<\/p>\n<pre>\r\n ! [remote rejected] master -> master (missing necessary objects)\r\nerror: failed to push some refs to 'http:\/\/192.168.1.115:3000\/org\/a-project.git'\r\n<\/pre>\n<p>In addition to that, I got a HTTP 500 when I try to view the repository details page via the dashboard.<\/p>\n<p>Since I can view my other repositories on my gogs git server, something must be wrong with a-project.git.<\/p>\n<p>Given that, here are the steps that I took to rectify the issue.<\/p>\n","protected":false},"author":1,"featured_media":2216,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"footnotes":""},"categories":[4],"tags":[311,255,195],"jetpack_featured_media_url":"https:\/\/www.techcoil.com\/blog\/wp-content\/uploads\/gogs-logo.png","jetpack_shortlink":"https:\/\/wp.me\/p245TQ-zI","jetpack-related-posts":[],"jetpack_likes_enabled":true,"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/2214"}],"collection":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/comments?post=2214"}],"version-history":[{"count":0,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/posts\/2214\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media\/2216"}],"wp:attachment":[{"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/media?parent=2214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/categories?post=2214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techcoil.com\/blog\/wp-json\/wp\/v2\/tags?post=2214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}