#git-atomic-commit
What does "atomic commit" mean and why does it matter on a team?
Что отвечать
An atomic commit is one commit that equals one logically complete change. You can describe it in a single sentence, and it **compiles and passes tests on its own**. Not a "WIP", not "fix typo + add feature + reformat". Why it matters: `git bisect` works only when every commit builds. Reverting one logical change becomes a single command. Review can understand "what exactly this commit did".
Что хотят услышать
A senior should: - name three criteria: one change, describable in a single phrase, builds and passes tests at its own point in history - explain the link to bisect: if commits are "bundled", bisect finds the commit but cannot tell what inside it is to blame - say that atomic does not mean "small": a 500-line commit can be atomic (a whole DB migration), and a 5-line one may not be (fix typo + add unused import) - name the discipline tools: `git add -p` to stage in chunks, `git commit --fixup=<sha>` for a targeted correction, interactive rebase to split a large commit into parts - mention that on teams with squash-merge atomicity is lost on main, but still matters for review before the merge
Подводные камни
- ✗ Saying "atomic means a small commit". Size is not the criterion, the criterion is "one logical change"
- ✗ Making a "refactor + new feature" commit. A revert later then needs to be rewritten by hand
- ✗ Skipping `git add -p` for speed and cramming edits to several unrelated files into one commit
Follow-up
- ? How do you split a large commit into a series of atomic ones with interactive rebase?
- ? How does `git add -p` help you make atomic commits?
- ? What happens to `git bisect` in a repository with broken commits?
Глубина в базе знаний