Lab 5

Rewriting (Git) History

The goal of this lab was to clean up our project- Urltester, by refactoring the code. That is, refactor the code so that it’s easier to read, maintain and modular. This involved three steps:

Creating a refactoring branch

git checkout -b refactoring master

This command made an isolated refactoring branch. I made the following changes to my code, and after each change I committed it with an appropriate message.

  • Removed variable ignore that wasn’t being used
  • Moved the styling that was used to display the version and tool name to a separate file style.js
  • Renamed a function that printed coloured output to console from coloredOutput to printColoredOutput
  • Renamed function that displays manual from messageOne to printManual
  • Fixed indent and use of whitespace for consistency
  • Renamed function that ignored urls provided to it from ignoreFilter to ignoreUrlsFilter

After doing this when I ran the command git rebase master -i

This opened an editor where I squashed the last 5 commits (squash) into the first (pick) and saved the file. I had to tackle with merge conflicts but I had already learnt how to deal with them so it wasn’t too hard for me. And then I did

  • git commit --amend
  • git checkout master
  • git merge refactoring
  • git push origin master

Now, when I went to remote git repo online, I saw the following commit message for the commits I had done which was not how it was supposed to look.

The actual ‘clean up’

Now, I had to do something. This wasn’t how it was supposed to look. I panicked and contacted my professor on Slack, showed him this picture and he said you can solve this using git commit --amend

So, I ran the command – git commit --amend and the editor opened

I had the video posted by my professor on the side, and I realized I hadn’t done this properly the last time and that is why my commit message was messed up. So, I did it right this time and force pushed it to origin

git push origin master -f

I looked up origin master again and I saw I forgot to edit the last line ‘Refactoring index.js to improve code maintability’

So, I did the above steps again – changed the commit message and force pushed the changes to origin master and I could see the desired result…

Published by Muskan Shinh

Software Development student at Seneca College

Leave a comment

Design a site like this with WordPress.com
Get started