DEV Community

Kannav Sethi
Kannav Sethi

Posted on

Refactoring, Git Rebase and Amends

One of the things that I learned this week was Technical Debt, which refers to how a developer compromises on good code to ship faster. To resolve this, I took on the task of refactoring my code for DialectMorph

Technical Debt In My Codebase

The CLI tool was working but many features in the codebase itself could have been implemented in a much better way that would provide more modularity and encapsulate the logic in classes rather than having magic variables

Interface for same closely linked classes

The tool utilized two different AI clients, and for both of them there were other classes. To unify and have better encapsulation, I decided to make an interface that these classes could inherit from, particularly a base AIClient interface.

Composite Class

The problem that I had in the program was that I was using a global variable to keep track of the AI client that my program was utilized, but this wasn't good because all of the logic to initialize a client was not encapsulated but rather spread out, so I built a composite class to encapsulate all the logic for the client

Config settings and file management

My config settings for the CLI tool were in the main file that had the same main function as the CLI tool, this was making my main file unnecessarily big, so what I did was I moved them out to a different file to make it more readable and accessible.

Git Rebase

After I was done with all of these commits, since all of them were centered around the same issue, that is refactoring code, I used the following command

(refactoring) -> git rebase main -i
Enter fullscreen mode Exit fullscreen mode

doing so I picked the first commit to represent a single commit and squashed all of those into a single commit, doing so helped me have a better commit history

Amends

Git rebase was fun to execute but I forgot to include a meaningful message that would be more descriptive of the changes that I had made, so to achieve that I did the following

(refactoring) -> git commit --amend
Enter fullscreen mode Exit fullscreen mode

this brought up my editor to edit the commit message and provide a descriptive message, doing so created a new commit that contained all of the changes from my previous rebased commits.

Conclusion

After all of this was done, I wanted to merge the changes on my local branch, and since no changes were made to the main branch, the merge would, be a fast-forward merge, so I used the following commands to merge the changes in the main of my local branch

(refactoring)-> git checkout main
(main)-> git merge --ff-only refactoring
Enter fullscreen mode Exit fullscreen mode

this merged the changes into my main branch, after which I had pushed to the GitHub repository, to have a look at this commit click here

To be completely honest, this was a fun week, It cleared the initial perspective that I had for the rebase command in git, made me realize how git commits can be changed as well, and the most important part, which was technical debts

Top comments (0)