Welcome back to another blog post of mine! This week has been very eventful for me despite it is only midweek. I was interviewing with a company that I really like on Monday for round 1, then made it to round 2 on Tuesday and received the offer on Wednesday. You can imagine I was walking on Cloud Nine when received the news. I really appreciate the management quick approach because it means now I can completely focus on improving my skills so I can contribute more values in my placement.
Back to Topic of Open Source, this week we have learned about another power Git command which is git rebase. Before knowing this command, I often ran into situation that I made the too many commits also with random commit messages. It makes my Git history look like a kid playing with GitHub. So long those times!
Lab 5 asked us to refactor our code and apply git rebase to combine multiple commits into a single commit before merging into master branch. Since I started my codes with modularization in mind, my codes were already in a certain structure. My first change was to create a better file structure as I notice I have some orphan test files that contains data for test run. Those file should belong to a test folder. I also changed the helpers folder name to lib to reflect better its purpose. I complained a lot about how my linkDetector.go file became heavy as I added more features. My second task was to slim it down. I spent sometimes to think about what I should do and noticed how the majority of codes in this file is for the features of the app. If I could put all of these codes to a features package and each feature will be represented by a function, my code would be much cleaner. I decided to create a features folder under lib folder and put all the feature codes there. My last change was to separate functions in utils package more. I noticed I can separate all the parser functions into a separate file called parsers.go. This increases the understandability of my code and prevent confusion for other developers while reading my code. In total, I made three separate commits for three changes.
At this moment, I had three commits. It was time to use git rebase to combine them into one single commit. After I ran git rebase master -i, it prompted me to choose what to do with the commits, I squashed the first two commits so they could merge be merge into the last one. It then prompted me to the below panel. I then saved the file and closed it.
Here is my Git history after rebasing:
It maintained the commit message of all three commits. I then ran git commit — amend to modify the commit message as belows.
My final task was to merge this refactored branch into the master by simply switch to master branch and run git merge refactoring. The result of the merge show updated the master branch to the same commit as in refactoring branch. I then run git push origin master to update the remote master. And that’s it for lab 5.
Phwwww! That was another TL, DR blog. I wished I could have written less, but I learned a lot through the process, it increased proportionally my writing. Now I won’t make silly mistakes like before and even if I made a mistake, i could always depend on git rebase to save myself on a rainy day.
I will be back again next week for another TL,DR post. Thank you for reading.
It’s time to cherish myself for what I have achieved :).
Tony Vu.