How can I merge two commits into one if I already started rebase?

 

If you have already started a rebase operation and want to merge two commits into one during the rebase process, you can use Git's interactive rebase feature. Here's a step-by-step example:

Suppose you have a commit history like this:

mathematica
A -- B -- C -- D -- E (your branch)

You want to merge commits C and D into a single commit. You've already started a rebase with the command:

bash
git rebase -i HEAD~5
  1. When you run this command, Git opens an interactive rebase file in your text editor. It looks something like this:

    bash

Comments