<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Git on ~/kd8bny</title>
    <link>https://kd8bny.com/tags/git/</link>
    <description>Recent content in Git on ~/kd8bny</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>Daryl Bennett. All Rights Reserved.</copyright>
    <lastBuildDate>Wed, 30 Jul 2025 15:04:10 -0500</lastBuildDate>
    <atom:link href="https://kd8bny.com/tags/git/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>0x0001 Don&#39;t reset, revert with git</title>
      <link>https://kd8bny.com/bytes/0x0001_git_revert/</link>
      <pubDate>Wed, 30 Jul 2025 15:04:10 -0500</pubDate>
      <guid>https://kd8bny.com/bytes/0x0001_git_revert/</guid>
      <description>&lt;p&gt;Every so often one will run into a situation where someone made some mistakes and you really just need to roll back in the git history.&lt;/p&gt;&#xA;&lt;p&gt;One may be in distress, maybe do a haphazard search something something “reset my branch to previous commit” and click the first stack overflow link. Another may ask the AI overlords for advice. Both cases often end with the bad advice of the “force push”. &lt;em&gt;sigh&lt;/em&gt;&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git reset &amp;lt;commit sha&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push -f origin main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This unassuming sequence of commands could get you to your desired state, but at a cost. The version history will be rewritten. One could experience data loss or make distributed contributions troublesome with divergent histories. If we learned anything from time travel tropes: don&amp;rsquo;t mess with history!&lt;/p&gt;&#xA;&lt;p&gt;Fret not, for there is an easier way.&#xA;git provides us with a revert. A revert will function similarly to reset, however it will create a new commit with the appropriate delta between the HEAD and the desired point in history. Since a new commit is created history remains unaffected and allows one to restore to a previous point in your branch.&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git revert &amp;lt;commit sha&amp;gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;git push origin main&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;–daryl&lt;/p&gt;&#xA;</description>
    </item>
  </channel>
</rss>

