Home > Enterprise >  Why I need small Git commit every time?
Why I need small Git commit every time?

Time:03-31

I am a newbie and please forgive me if this is a valid question.

I am learning git and reading best practices from here https://acompiler.com/git-best-practices

My question is why does atomic commit?

If I am working on a story and it takes 10 days to finish how can I commit before it complete? I am bit confused. Thanks for your help in advance.

CodePudding user response:

An "atomic" commit is easier to handle in the case you want to revert, cherrypick or merge it. The changes of the commit are clear and understandable.

If your commit contains changes that alter an algorithm and file handling, you can't separate the changes of the algorithm from the file handling, making it difficult revert the file handling changes (or the algorithm).

If your commit contains only partial changes so your program is not in a stable state with this commit, it is difficult to comprehend what commits are actually needed to change in the case something goes wrong.

Let's say your program changes file handling but your commit is incomplete and thus it only changes the path of the file and not the format of the file. All other people who work on that project can't continue/debug your program, since the file format actually changed, but it isn't visible in the commits.

CodePudding user response:

simply like this, to make it easier to manage or repair a file, if at any time there is a conflict in making changes or merging files, you can still return to the previous commit without having to create it from scratch again

  • Related