Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.4k points)

I am trying to merge 2 commits into 1, so I followed “squashing commits with rebase” from git ready.

I ran

git rebase --interactive HEAD~2

In the resulting editor, I change pick to squash and then save-quit, but the rebase fails with the error

Cannot 'squash' without a previous commit

Now that my work tree has reached this state, I’m having trouble recovering. The command git rebase --interactive HEAD~2 fails with

Interactive rebase already started

and git rebase --continue fails with

Cannot 'squash' without a previous commit

1 Answer

0 votes
by (27.5k points)

I am assuming that you were in your own topic branch. Now, if you want to merge the last 2 commits into one, branch off the commit just before you made the last two commits.

$ git checkout -b temp_branch HEAD^2

Now perform squash commit the other branch in this new branch:

$ git merge branch_with_two_commits --squash

This should bring in the changes but will not commit them. So now just commit them and you're done.

$ git commit -m "Add your message"

You are good to merge this new topic branch back into your main branch

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94.2k users

Browse Categories

...