Hi, I'm Torham(my nickname), welcome to this article. In this article, we want to examine a concept called atomic commit. There are as many different explanations for this concept as there are programmers on the planet. Every programmer has a different view on committing and especially atomic commit, But some concepts about this topic are common. So let's take a look at these concepts and the views of some other programmers.
What is atomic commit?
In simple words, we can say that atomic commit means that you make a commit for every small change. But it doesn't mean that you have to commit one code to change each character :) And this is exactly where the different views of each programmer begin.
Some programmers believe that you should create a commit by making changes to each function, and some believe that you should not settle for one function, but have a different view of each code. For example, in a source code, many things happen by changing a line while you haven't edited any function, so you have to determine the time of each commit with a more conceptual view of the code. I think you have to see if the change you are making is completely trivial or if will it cause a lot of changes or ambiguity.
If the change you make is very unimportant, such as a change in characters or very small changes like this, there is no need to commit and you can go to the next change and then commit the previous changes in a more important change.
But the important thing is to commit immediately after that important change and then continue editing the code.
In the field of computer science, an atomic commit is an operation that applies a set of distinct changes as a single operation. If the changes are applied, then the atomic commit is said to have succeeded.
How to write an atomic commit?
After we understand what atomic commit is. It is better to see how an atomic commit is written.
We know that we create each atomic commit for one change in the source code. Let's assume I made some changes to the function that is responsible for calculating users' income. According to this change, from now on we will deduct 10% of income above $100 as tax (this is just an example :)).
And for this change I have written the following commit:
$10 is deducted from income above $100 as tax
By subtracting 10 dollars from the income variable of users above $100
Task ID : #re423f
Ok, let's check the commit above.
At first glance, you will see a 3-line text! Yes, atomic commits are written in a maximum of 3 lines and a minimum of 2 lines. In the first line, we explain the change we have made with a maximum of 50 characters, in the second line, we give a supplementary explanation about the change made with a maximum of 75 characters. And in the last line, the ID of the task for which we have made this change. Written
The last line can be different depending on the company you work in. Some companies have a special ID for their tasks.
Why 50 and 75 characters?
As I said, you should write the first line in a maximum of 50 characters and the second line in a maximum of 75 characters. But for what reason? This limitation is because GitHub or GitLab usually shows 50 characters completely as a title, and we don't need to click on the commit button to read the full title.
And since the description should not be too long, 75 characters is the limit for the second line, but you can be a little less sensitive about the number of characters in the second line.
Why use atomic commit?
But why should we bother ourselves so much and use atomic commit? This style of commit makes the changes readable and clear in tools like GitLab and GitHub, and you will have an easier time finding a bug and the culprit of that bug because each change has a commit and a clear explanation is written for it.
And the most important reason why you should use atomic commit is that companies love atomic commit :) When you tell your manager that you use atomic commit, his eyes light up and he says to himself, I found my amazing programmer. ( This is very important ๐ )
Final words
I repeat that there are different views about atomic commit, I shared my view and experience with you. If you have more knowledge or experience, you can write us your comment :)
I hope you enjoyed this article and don't forget that atomic commit makes you a more professional programmer. Writing atomic commits is indeed time-consuming and you may not like to do this, but I must say that after some time you will see that atomic commits will help not only the company but also yourself.
hoping for freedom โค๏ธ