We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

How to Squash

Perhaps confusingly, squashing is done with the git rebase command! Here are the steps to squash the last n commits:

  1. Start an interactive rebase with the command git rebase -i HEAD~n, where n is the number of commits you want to squash.
  2. Git will open your default editor with a list of commits. Change the word pick to squash for all but the first commit.
  3. Save and close the editor.

The -i flag stands for "interactive," and it allows us to edit the commit history before Git applies the changes. HEAD~n is how we reference the last n commits. HEAD points to the current commit (as long as we're in a clean state) and ~n means "n commits before HEAD."

Why Does Rebase Squash?

Remember, rebase is all about replaying changes. When we rebase onto a specific commit (HEAD~n), we're telling Git to replay all the changes from the current branch on top of that commit. Then we use the interactive flag to "squash" those changes so that Rebase will apply them all in a single commit.

Assignment

MegaCorp executives do not like your last few commits. As a result, your manager has told you to squash your last 3 commits (J, L, and K) into a new single commit with the message J: redacted.

Squashing is a destructive operation, which is why you've decided to make the change on temp_main before moving it to main.

Run and submit the CLI tests.