Hotfix with Git Cherry-Pick

Hotfix with Git Cherry-Pick

Daily short news for you
  • Privacy Guides is a non-profit project aimed at providing users with insights into privacy rights, while also recommending best practices or tools to help reclaim privacy in the world of the Internet.

    There are many great articles here, and I will take the example of three concepts that are often confused or misrepresented: Privacy, Security, and Anonymity. While many people who oppose privacy argue that a person does not need privacy if they have 'nothing to hide.' 'This is a dangerous misconception, as it creates the impression that those who demand privacy must be deviant, criminal, or wrongdoers.' - Why Privacy Matters.

    » Read more
  • There is a wonderful place to learn, or if you're stuck in the thought that there's nothing left to learn, then the comments over at Hacker News are just for you.

    Y Combinator - the company behind Hacker News focuses on venture capital investments for startups in Silicon Valley, so it’s no surprise that there are many brilliant minds commenting here. But their casual discussions provide us with keywords that can open up many new insights.

    Don't believe it? Just scroll a bit, click on a post that matches your interests, check out the comments, and don’t forget to grab a cup of coffee next to you ☕️

    » Read more
  • Just got played by my buddy Turso. The server suddenly crashed, and checking the logs revealed a lot of errors:

    Operation was blocked LibsqlError: PROXY_ERROR: error executing a request on the primary

    Suspicious, I went to the Turso admin panel and saw the statistics showing that I had executed over 500 million write commands!? At that moment, I was like, "What the heck? Am I being DDoSed? But there's no way I could have written 500 million."

    Turso offers users free monthly limits of 1 billion read requests and 25 million write requests, yet I had written over 500 million. Does that seem unreasonable to everyone? 😆. But the server was down, and should I really spend money to get it back online? Roughly calculating, 500M would cost about $500.

    After that, I went to the Discord channel seeking help, and very quickly someone came in to assist me, and just a few minutes later they informed me that the error was on their side and had restored the service for me. Truly, in the midst of misfortune, there’s good fortune; what I love most about this service is the quick support like this 🙏

    » Read more

The Issue

I must say that ever since I learned how to use Git, I no longer need to copy the project to a new folder for "backup" every time I'm about to make a major change. Back in the days when I didn't know Git, that was the method I could come up with to safeguard my code in case there was a bug and I needed to revert.

Git is a version control tool that I believe is highly effective for most programmers. One of Git's standout features is its ability to create commits, which you can think of as "commitments," for each line of code you add. Each of these commitments is recorded in the history and can be easily reviewed, allowing you to return your code to that state.

For each individual or organization, there are different ways to use Git, creating diversity in workflows. "Flow" is a term that denotes the work process in Git. The most common example is having a master branch as the main branch, a development branch for ongoing development, and branches with prefixes like feature/01, feature/02... These branches are created from the development branch for continuous deployment of new features.

"Hotfix" is also a prefix in branches used to fix a specific issue in a production environment. After releasing an application, there might be an unexpected issue that requires an immediate fix. Such issues are considered critical and need to be addressed as a top priority. Typically, the solution is to check out a hotfix branch from the master branch, for example, hotfix/01, fix the issue, test it, and if everything is fine, merge hotfix/01 into both the development and master branches.

That's in the case when we've just finished a release and discovered a bug, or at least when the time between discovering the bug and the changes on the development branch isn't too extensive compared to the master branch. Conversely, if the development branch has undergone too many changes due to continuous feature development by the team, then the possibility of conflicts arising when merging a hotfix into the development branch becomes a concern.

This situation is also understandable because the new features may have modified the code at a different location than the master branch. When the master branch is "outdated," and a hotfix is merged, conflicts are likely to occur. To address this scenario, we need a method called "cherry-pick" for hotfixes.

Git Cherry-Pick

git cherry-pick is a Git command used to apply one or more commits from one branch to your current branch. This allows you to apply specific changes from commits without having to merge the entire branch.

For example, if you have a commit on a latest development branch that resolves a specific issue you need to apply to your product branch, you can use git cherry-pick to apply that commit to your current branch.

git cherry pick

Normally, when merging one branch into another, Git will take all the changes from the commits to merge. However, with "cherry-pick," you can select a single commit to bring into your branch.

Applied to the hotfix scenario mentioned above, we create a hotfix branch from the development branch, make the necessary code changes, commit them, and then cherry-pick that commit into the master branch.

To explain further, because the development branch always contains code newer than or equal to the master branch, creating a hotfix from the development branch, making the changes, and only "picking" that commit into the master branch reduces the risk of conflicts.

In a broader context, cherry-pick is not limited to hotfixes; it can be used in various other situations whenever you need to "pick" a commit into a specific branch without merging the entire branch.

Conclusion

git cherry-pick is used to apply one or more commits from one branch to another. In this article, we are discussing the use of cherry-pick for hotfixes, especially when the development branch has diverged significantly from the master branch and contains many changes. Instead of merging a hotfix from the master into the development branch, which can lead to code conflicts, we create a hotfix from the development branch and cherry-pick the commit into the master branch, reducing the risk of conflicts.

Premium
Hello

5 profound lessons

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

Every product comes with stories. The success of others is an inspiration for many to follow. 5 lessons learned have changed me forever. How about you? Click now!

View all

Subscribe to receive new article notifications

or
* The summary newsletter is sent every 1-2 weeks, cancel anytime.

Comments (0)

Leave a comment...