DEV Community

Franz Wong
Franz Wong

Posted on

2 1

Fix "cannot 'squash' without a previous commit" for Git

Suppose you create a new codebase and you have only 2 commits. Now you want to combine the 2nd commit to the 1st commit with this command.

git rebase -i HEAD~1

However, Git cannot perform that and it returns an error message like this.

error: cannot 'squash' without a previous commit

For this case, you should try this.

git rebase -i --root

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay