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.
4 replies
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.