<?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: highfadehq01</title>
    <description>The latest articles on DEV Community by highfadehq01 (@highfadehq01).</description>
    <link>https://dev.to/highfadehq01</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%2F3899096%2F930cbc98-2b23-490a-bbea-d88c2d9fb80b.png</url>
      <title>DEV Community: highfadehq01</title>
      <link>https://dev.to/highfadehq01</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/highfadehq01"/>
    <language>en</language>
    <item>
      <title>How to Undo a Git Commit (The Right Way)</title>
      <dc:creator>highfadehq01</dc:creator>
      <pubDate>Mon, 27 Apr 2026 03:50:08 +0000</pubDate>
      <link>https://dev.to/highfadehq01/how-to-undo-a-git-commit-the-right-way-44po</link>
      <guid>https://dev.to/highfadehq01/how-to-undo-a-git-commit-the-right-way-44po</guid>
      <description>&lt;p&gt;Searching "how to undo a git commit" returns 10 Stack Overflow answers with different commands and no explanation of which to use when. Here is the decision tree.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Did you push the commit?
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;No, it is only local.&lt;/strong&gt; You have the most options. Use git reset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Keep your changes staged (safest — nothing is lost)&lt;/span&gt;
git reset HEAD~1 &lt;span class="nt"&gt;--soft&lt;/span&gt;

&lt;span class="c"&gt;# Keep your changes unstaged but on disk&lt;/span&gt;
git reset HEAD~1 &lt;span class="nt"&gt;--mixed&lt;/span&gt;

&lt;span class="c"&gt;# Discard your changes completely (no recovery without reflog)&lt;/span&gt;
git reset HEAD~1 &lt;span class="nt"&gt;--hard&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Yes, it is already pushed.&lt;/strong&gt; Do not rewrite history on a shared branch. Use git revert instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git revert HEAD   &lt;span class="c"&gt;# undo the most recent commit&lt;/span&gt;
git push          &lt;span class="c"&gt;# push the undo commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Revert creates a new commit that inverts the changes. Your teammates see the history intact — they just also see the fix.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Was it multiple commits ago?
&lt;/h2&gt;

&lt;p&gt;If the commit you want to undo is not the latest, you need its hash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git log &lt;span class="nt"&gt;--oneline&lt;/span&gt;   &lt;span class="c"&gt;# find the hash&lt;/span&gt;
git revert abc1234  &lt;span class="c"&gt;# revert that specific commit&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Tip:&lt;/strong&gt; If you reverted the wrong commit, just revert the revert: &lt;code&gt;git revert HEAD&lt;/code&gt; again will undo the undo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: What if you used --hard and lost work?
&lt;/h2&gt;

&lt;p&gt;The reflog still has it. Git keeps a log of every HEAD position change, even across hard resets. Run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git reflog                          &lt;span class="c"&gt;# look for your commit in the list&lt;/span&gt;
git checkout &lt;span class="nt"&gt;-b&lt;/span&gt; recovered abc1234   &lt;span class="c"&gt;# put it on a new branch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The reflog retains entries for 30–90 days (configurable). As long as garbage collection has not run, the data is there.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://highfadefree.vercel.app/blog/undo-git-commit" rel="noopener noreferrer"&gt;High Fade Free&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>git</category>
      <category>beginners</category>
      <category>tutorial</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
