X

Headline

This is an important message requiring you to make a choice if you're based in the EU.

How to Combine Multiple Commits into One

An interactive rebase mode allows you to combine your commits into even one singular commit. If you wonder why you should do this, imagine a branch with a lot of commits that contain minor changes. The history will have a messy look like this:


This kind of history full of meaningless commits makes it difficult for your team to see your finished product. A quick solution is combining multiple commits into one. To do so, you should follow the steps below.

1. Run Git Rebase in Interactive Mode

Firstly, you should run the git rebase in interactive mode and provide the parent commit as the argument, like this:

git rebase -i HEAD~3

2. Type "Squash"

After the first step, the editor window will show up offering you to input the command for each commit. All you need to do is typing "squash" at the beginning of the second line and save the file:


3. Choose Between Commit Messages

One more editor window will show up to change the resulting commit message. There will be combined messages. If you want your second commit message to be the same as the first one, you can simply remove it and save the file, like this:


Do you find this helpful?

Related articles