DEV Community 👩‍💻👨‍💻

Yuan-Hsi Lee
Yuan-Hsi Lee

Posted on

Git Rebase

This week, we're refactoring our console app to practice git rebase and git amend.

After the first time publishing this console app, I found something that I can improve such as duplicate code design, bad formatting with too many spaces and newlines. Later on, my classmates and I added more features and changes to the console app and it bought more duplicate code. I kept telling myself I will definitely come back and fix them... one day.

And this is the day!

I made 3 changes for refactoring my program. Firstly, the missing file exception is thrown by all the options in my application. I made a customize exception to throw the exception message of something like "file missing..." with the input option name. Secondly, I extract the changing console output color and printing status with URL lines of code to a reusable function. I separate them into different colors. The red function is designed to bad/unavailable URL and the green function is designed to good/available URL). By passing the status name (good or available) and the URL, the output message can be customized. Lastly, I remove the extra spaces and newlines, and add the spaces after keywords to improve readability.

After making the above three commits, I use git rebase to squash them into one commit. Then, by using git commit --amend, the commit message is changed to the required format. For practicing git amend command, I intentionally neglect one changed file in my first commit and then use git add <neglected file> and git commit --amend --no-edit to add this file.

Top comments (0)

DEV

Thank you.

 
Thanks for visiting DEV, we’ve worked really hard to cultivate this great community and would love to have you join us. If you’d like to create an account, you can sign up here.