It makes reviewing a PR easier if all the commits in a PR are condensed down to
a set of distinct commit messages, even if they get squashed when being merged
anyway. See this as an opportunity to describe to the reviewer what you did when
implementing the change.
5 replies
Creating a clean set of distinct commits in a PR requires that atomic commits
were made in the first place. It's a good habit while developing to commit early
and commit often: create many small commits, which you then later can combine
into bigger ones.
A great helper to achieve this is using git add -p, which will go through all
current unstaged changes and let you decide which changed segment in a file to
stage. https://gist.github.com/mattlewissf/9958704
git add -p allows you to create multiple commits from a situation where you
have applied different changes while developing (a new feature here, but also a
bug fix, and maybe some formatting, or changes to the CI configuration).
What if you accidentally combined unrelated changes in one commit? There is a
way to split up these commits, but there is no reverse version of squash, it has
to be done manually. See the Splitting a commit section in the official Git
documentation. https://git-scm.com/book/en/v2/Git-Tools-Rewriting-History
Here again, when in rebase, git add -p is your friend.