Skip to main content

Revert Your Mistaken Git Commits

Today one of my development teams had a merge problem. We use GitFlow, and it was time to merge from the develop branch to the release branch. If things are done correctly, this should always be a clean, simple merge. It is especially true in this case, because it was our first release for this project, so the release branch should be empty. Except that it wasn’t. Huh?

As it turned out, a well-meaning developer on the team knew we were pushing our code into release, so that’s what he did. The output of `git log --oneline` on the release branch showed something like this:

      1 852291a blah blah blah
      2 f575c87 blah blah
      3 83d855d blah blah
      4 9fa11df blah blah blah blah
      5 111b003 blah blah
      6 2b3a530 blah blah blah
      7 a4c5f54 blah blah blah blah blah blah
      8 b2a62fa blah blah blah blah blah blah blah blah blah
      9 5fb67b9 blah blah blah
     10 4d1a5fc blah blah blah
     11 ed40aec Initial commit

No, we really don’t use “blah blah” as commit messages. The problem was that these commits were made directly to the release branch, and not through a merge or pull request from develop, which is the prescribed method. I don’t hold any grudges against the well-intended developer. GitFlow is new on that team, and I mostly blame myself for not setting up a 30-minute discussion ahead of time.

Regardless of my feelings or the good intentions of the team, I was faced with a problem I had to solve. The pull request was waiting. The test team was waiting for a release build, and that wasn’t happening. I decided that the best and safest thing to do was to undo each of those commits.

So after a bit of Google- and Bing-foo, I landed on some questions and answers at StackOverflow.com that enabled me to find just the right sequence of git commands to fix the release branch. I’m recording the experience here so that I know where to look the next time this happens, and in the hopes it may help someone else.

The first thing I had to do was figure out how to revert a series of commits. There were only 11, so I could have done them one at a time, but what if there had been 111 instead? I wanted to understand the process regardless of the number of commits. After reviewing the various commands that are available, I settled on the syntax `git revert ..`. This actually took a few tries, because most of the documentation said things like “first bad commit” and “last bad commit.” Is “first” the oldest, or is it #1 in the log? Turns out, it’s the oldest, which is the highest number in the commit log.

So, to undo all of those commits in the above list, I used the following commands:
 # git revert --no-edit ed40aec..852291a
 # git log --oneline

The --no-edit flag kept git from prompting me to edit the commit message for each of the 11 reverse commits it made. Instead, it used the original commit message, preceded by the word “Revert.” Fine by me. After that command completed, each of my commits had a mirrored revert, in reverse order. Checking the directory showed that the only thing present was the initial README.md file. Perfect! So the only thing left to do was push the branch back up to the server:
 #  git push origin release


Back on the server, I checked the open pull request from develop to release, and there were no merge conflicts. I completed the merge request, and the build was able to continue. Now the testers can get on with their work, and we can all live happily ever after — until the next problem, of course. 

Comments

Popular posts from this blog

How to copy your Frozen Free Fall progress to a new phone

It's happened to all of us. You are about to get a branch new smartphone, when it hits you. You're on level 250 of Frozen Free Fall. If you get a new phone, you'll lose all of that progress! Ok, admittedly this isn't the most pressing problem of our time, but it's annoying. So today I decided to do something about it.

I have a Samsung Galaxy S4 (Android), and just received an iPhone 5c. Before you bash me on my phone choice, let me explain that the iPhone is provided by my employer at no cost to me. Now you may proceed to bash me for putting games on my work phone. 
First step: Frozen Free Fall had already been installed on both devices. Next, using the Astro File Manager on my Galaxy, I searched and found the Frozen game save stored in /storage/sdcard0/Android/data/com.disney.frozensaga_goo/files/user.dat. I imagine it will be in the same location on any Android phone. If not, just look for user.dat in a folder with a similar name. So, using a USB cable and the A…

Ionic vs. Bootstrap - for a Web App

Ionic 1.x vs Bootstrap 3.x for a Web AppI was recently asked at work to come up with a comparison between Ionic Framework and a more traditional Angular/Bootstrap combination to create a web app. The application will primarily be used in a desktop web browser (probably Chrome or IE). There are also some use cases where it will be accessed from Safari on an iPad. However, this is purely a web; there are no plans to install the app onto the iPad as a hybrid app. Thus, recommending Ionic to build the UI hadn't occurred to me until the request was made.

This is even more surprising in that I recently published a Pluralsight course on Ionic Framework 1. It should have been the first thing that crossed my mind.
One constraint is that currently only Angular 1.x and Bootstrap 3 are authorized web technologies. Ionic 1.3 was recently approved, but not Ionic 2, Angular 2, or TypeScript yet.
Given those constraints, herein is my attempt at coming up with reasons to use (or not to use) Ionic…

Windows 10/Server 2016 100% Disk on BootCamp and Parallels!

I've been wrestling with Windows on my 2014 Mac Mini for more than two years. Soon after I bought the Mac, I made a 200GB BootCamp partition and installed Windows 7. I also bought Parallels 10 Desktop and pointed it at the BootCamp partition. It was great. I had a convenient VM when I needed something quick. I also had BootCamp when I needed native performance. Not long after that, I upgraded it to 8.1. Then sometime later, Windows 10.

I don't remember exactly when it happened, but one day I fired up Parallels and my entire system ground to a halt. Shutting down the virtual machine caused everything to go back to normal, so I figured the problem was with Parallels. So I upgraded it. Same problem. I made sure Windows was up-to-date, thinking that maybe the Windows Update service was going nuts. Nothing changed. Whenever Windows was running in Parallels, the Task Manager showed the disk activity pegged at 100%.

I tried all sorts of online solutions, but none worked. On a whim, I…