Search⌘ K
AI Features

The 'git rebase -i' Command

Explore the git rebase -i command to understand how to squash multiple commits into a single one, navigate commit history references, and manage branch pointers. This lesson guides you through interactive rebasing's common commands and warns about the implications of pushing squashed commits to remote repositories.

In order to squash a set of commits, you need:

  • A reference to the last (latest) commit of the set you want to squash.
  • A reference to the oldest (first) commit of the set you want to squash.

You already have a stable reference to the latest commit, i.e., where we are at the moment. Can you remember what it is?

You need a reference to the oldest commit in the history. Can you find a way to get it?

Reference to oldest commit

There are many ways to do it. The way we’re going to find it is to use the git rev-list command. You should be at the point where you’re comfortable reading up on a Git command, so go off and do that now.

OK? Now, run this command:

1	git rev-list --max-parents=0 HEAD

That gets you the original commit, and that’s the method you’re going to use here.

The following command will substitute the output of that command into the git rebase command ...

Terminal 1
Terminal
Loading...

Don’t worry about ...