7 ms·
I often have several "topics" going on in the same branch, for which there are existing (unpublished) commits. When I make some small change, it usually belong
by kazinator 5y ago
I often have several "topics" going on in the same branch, for which there are existing (unpublished) commits.
When I make some small change, it usually belongs to one of these topics. If it's the topmost commit, of course it can be combined into it with "git commit --amend --patch".
If the small change for one of the commits behind that one, then I make fixup commits with "git commit --fixup <hash>" or "git commit --fixup HEAD^^^" (as many carets as needed to refer to the commit I want).
If the little fix requires an addition to the commit message, then --squash instead of fixup.
These little fixup/squash commits can then be squashed into their target commits using "git rebase -i --autosquash".
That may be how some of your coworkers have clean histories.
In some environments, a change made up of numerous little commits like "fix typo" wouldn't pass peer review ; you're supposed to know ho to squash things together (but not too much so that topics get inappropriately combined).
Some shops have a policy that every commit has to build and possibly also pass the test cases. So you can't have an "oops, add missing semicolon" commit; its parent wouldn't build.
Commits should be like Stack Overflow answers: "is this useful to future visitors of this git history?"