How to combine two or more git commits into one
To combine multiple Git commits into one, you can rebase interactively. Choose some commit
that is farther back in your history than any of the commits you want to combine, and pass it to git rebase
:
You will get a list of your commits in the editor. For example, something like this:
pick c81bf8b7 Fix wrong harbulary battery insertion instructions
pick 97b462c8 Fix typo in harbulary battery insertion instructions
pick 6ce6071c Add battery diagram in chassis design
pick f2c8d028 WIP boost search results for context fields
A tip about interactive rebasing
Avoid regular rebasing (adding some other branch’s commits into the history of your branch) and
interactive
rebasing (changing commit order, commit messages, squashing, etc.) in the same step. When you’re trying to get commits from
another branch into your branch, just rebase without any adjustment/interaction. Only rebase interactively against
a commit that’s already in your branch’s history (i.e. a
fast-forward commit).