<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Akash Kumar</title>
    <description>The latest articles on DEV Community by Akash Kumar (@theakash04).</description>
    <link>https://dev.to/theakash04</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1240102%2F69a477f8-782c-4dac-9ae8-01011201bcb9.jpg</url>
      <title>DEV Community: Akash Kumar</title>
      <link>https://dev.to/theakash04</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/theakash04"/>
    <language>en</language>
    <item>
      <title>Git Gone Wrong: How I Lost My Code and Found My Sanity (Sort Of)</title>
      <dc:creator>Akash Kumar</dc:creator>
      <pubDate>Fri, 15 Nov 2024 23:25:54 +0000</pubDate>
      <link>https://dev.to/theakash04/git-gone-wrong-how-i-lost-my-code-and-found-my-sanity-sort-of-5b9i</link>
      <guid>https://dev.to/theakash04/git-gone-wrong-how-i-lost-my-code-and-found-my-sanity-sort-of-5b9i</guid>
      <description>&lt;p&gt;Just lost all my code today! 😱 After a long day of coding, I pushed my changes to Git—did the usual &lt;code&gt;git add&lt;/code&gt;, &lt;code&gt;git commit&lt;/code&gt;, and then &lt;code&gt;git push&lt;/code&gt;. Everything seemed fine, so I switched back to my working branch, thinking the post was safely committed. But then I saw it... the nightmare—no recent commit. 😨&lt;/p&gt;

&lt;p&gt;I was like, "What the heck just happened?" My code was gone! I checked my terminal (I use Linux, by the way), and saw that my local changes had been merged with the GitHub code. Everything was lost.&lt;/p&gt;

&lt;p&gt;After some frantic Googling and reading through Git docs, I learned that if you’ve switched branches recently, Git still keeps the previous state saved. Phew!&lt;/p&gt;

&lt;p&gt;I ran &lt;code&gt;git show ORIG_HEAD&lt;/code&gt;, and luckily, I found the lost state. Then, I created a branch from that commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch recovered-work ORIG_HEAD
git checkout recovered-work
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, I discovered &lt;code&gt;git fsck&lt;/code&gt;, which can help find dangling commits. There it was, a dangling commit with all my changes. I verified it with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git show &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, I created a branch from that commit:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git branch recovered-work &amp;lt;commit-hash&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And merged it back into main. Crisis averted!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lesson learned&lt;/strong&gt;: Always double-check your branches before committing. Git is powerful, and recovery is possible when things go wrong. 💡&lt;/p&gt;

&lt;p&gt;Hope this helps you all, and one thing: Don’t be dumb like me! Be careful with merging, pulling, and pushing to GitHub. 😅&lt;/p&gt;

</description>
      <category>git</category>
    </item>
  </channel>
</rss>
