0

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.

Coder
  • 11
  • 2
  • Your story will not be one gigantic leap, but will rather be a series of smaller steps. Each of them should be their own commit. – j6t Mar 30 '22 at 05:48
  • You don't *need* small commits, in the same way that I can write your biography as "you were born, lived, and then died". :-) You probably *want* more than that. – torek Mar 30 '22 at 18:28

2 Answers2

6

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.

Raildex
  • 3,406
  • 1
  • 18
  • 42
  • 3
    It's worth adding that commits that make your repository "incomplete" (as in, a half-implemented feature that prevents your current code from working correctly) would be done in a branch, which would be merged when the repository contents are brought back to a usable state. This means, anyone who needs your code in a workable state can still access it, despite the developers committing tiny sections that temporarily break things. – Amadan Mar 30 '22 at 05:47
1

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

Diar J R
  • 41
  • 3