<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Anand Setty on Medium]]></title>
        <description><![CDATA[Stories by Anand Setty on Medium]]></description>
        <link>https://medium.com/@anandsetty?source=rss-7ea4faf4085f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*TLnTsqmJsueOwt_t.</url>
            <title>Stories by Anand Setty on Medium</title>
            <link>https://medium.com/@anandsetty?source=rss-7ea4faf4085f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 15:50:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@anandsetty/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Interactive Rebase Can Save the Day: A Guide to Reverting Unwanted Changes]]></title>
            <link>https://medium.com/@anandsetty/how-interactive-rebase-can-save-the-day-a-guide-to-reverting-unwanted-changes-7326715af696?source=rss-7ea4faf4085f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7326715af696</guid>
            <category><![CDATA[git-commands]]></category>
            <dc:creator><![CDATA[Anand Setty]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 17:06:33 GMT</pubDate>
            <atom:updated>2024-10-21T17:16:37.889Z</atom:updated>
            <content:encoded><![CDATA[<p>Ah, the life of a software developer — where your code is pristine one minute and a chaotic mess the next. You’re merrily coding away, merging feature branches into your release branch, when suddenly, you hit a wall. A bug, courtesy of one of your shiny new commits from <strong>Feature Branch 1</strong>, emerges from the depths of production, ready to wreak havoc. Panic sets in, but fear not! Git has a hidden gem: <strong>interactive rebase</strong>. Let’s explore how this powerful tool can help you revert those unwanted changes while keeping your sanity intact.</p><h3><strong>The Scenario: The Great Merge Fiasco</strong></h3><p>Picture this: you have two feature branches:</p><blockquote><em>-</em><strong><em> Feature Branch 1: </em></strong>The “Shiny New Feature”<br><strong>- <em>Feature Branch 2: </em></strong>The “Other Not-So-Shiny Feature”</blockquote><p>After rigorous testing (well, mostly just crossing your fingers and hoping for the best), you merge both branches into the <strong>Release Branch</strong>. Everything seems perfect — until someone yells, “Mayday!” because your last commit in <strong>Feature Branch 1</strong> just caused the app to crash. What now? Do you scream into a pillow? Not quite! Let’s fix this with interactive rebase instead.</p><p><strong>Step-by-Step: Reverting a Commit Using Interactive Rebase</strong></p><p><strong>Step 1: Identify the Commit</strong></p><p>First, we need to find that pesky commit that threw a wrench in your plans. You can check your commit history with:</p><blockquote><strong>git log — oneline</strong></blockquote><p>Look for the commit hash of the culprit. For this example, let’s say it’s `a1b2c3d`.</p><p><strong>Step 2: Start Interactive Rebase</strong></p><p>Next, we’re going to start an interactive rebase to go back just before that commit. It’s like hitting the rewind button on a cassette tape — remember those?</p><blockquote><strong>git rebase -i a1b2c3^</strong></blockquote><p>The caret (`^`) indicates we want to go one commit back. It’s not a time machine, but it’ll do!</p><p><strong>Step 3: Editing with `vi`</strong></p><p>When you run the above command, the `vi` editor will open, displaying a list of commits, looking something like this:</p><blockquote><strong>pick</strong> a1b2c3d Commit from Feature Branch 1<br>pick d4e5f6g Another Commit<br>pick h7i8j9k Commit from Feature Branch 2</blockquote><p><strong>Now, let’s make some changes!</strong></p><p>Using `vi` Commands on macOS</p><p>1. <strong>Enter Insert Mode</strong>: Press `i` to enter insert mode. You can now make changes. This is the part where you channel your inner coder.</p><p>2. <strong>Change `pick` to `drop`:</strong> Find the line with the problematic commit and change `pick` to `drop`. Like so:</p><blockquote><strong>drop</strong> a1b2c3d Commit from Feature Branch 1<br> pick d4e5f6g Another Commit<br> pick h7i8j9k Commit from Feature Branch 2</blockquote><p>Boom! You just decided to “drop” a commitment. Who knew coding could feel so liberating?</p><p>3. <strong>Save and Quit:</strong> Press `Esc` to exit insert mode, then type `:wq` and hit Enter to save your changes and quit `vi`. You’ve successfully cut out the bad commit, and now you can finally breathe again!</p><p><strong>Step 4: </strong>Complete the Rebase</p><p>After saving and quitting, Git will reapply the remaining commits. If there are conflicts, you can resolve them like the pro you are. Once you’ve ironed out those wrinkles, continue the rebase with:</p><blockquote>git rebase — continue</blockquote><p><strong>Handling Empty Commits</strong></p><p>If, by some miracle, you encounter an empty commit (perhaps it was an “I-was-on-a-coffee-break” commit), Git will pause the rebase and prompt you with a message. To skip the empty commit, just type:</p><blockquote>git rebase — skip</blockquote><p>This command tells Git, “Nah, I’m good — let’s move on!” It’s like hitting the “snooze” button on that annoying alarm.</p><h4><strong>Summary of Commands</strong></h4><p>Here’s a handy recap of the commands you’ll use to reclaim your code:</p><p>1. Start interactive rebase:</p><blockquote>git rebase -i &lt;commit ID&gt;^</blockquote><p>2. In vi:<br> — Press “i” to enter insert mode.<br> — Change “pick” to “drop” for the commit you want to remove.<br> — Press “Esc”, then type “:wq” to save and quit.</p><p>3. Continue the rebase:</p><blockquote>git rebase — continue</blockquote><p>4. If you encounter an empty commit:</p><blockquote>git rebase — skip</blockquote><p><strong>Before and After Example in `vi`</strong></p><p><strong>Before:</strong></p><blockquote>pick a1b2c3d Commit from Feature Branch 1<br>pick d4e5f6g Another Commit<br>pick h7i8j9k Commit from Feature Branch 2</blockquote><p><strong>After (removing the problematic commit):</strong></p><blockquote>drop a1b2c3d Commit from Feature Branch 1<br>pick d4e5f6g Another Commit<br>pick h7i8j9k Commit from Feature Branch 2</blockquote><h3><strong>Conclusion</strong></h3><p>Interactive rebase is like a magic wand for developers, allowing you to clean up your commit history without the drama of a full reset. It’s a lifesaver when you need to drop unwanted changes and keep your project on track. So the next time you find yourself facing a “Mayday” moment, remember: interactive rebase is here to help. Grab your favorite coffee, put on your coding cape, and get to work — your code will thank you!</p><p>Happy coding!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7326715af696" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>