tibbus tibbus - 11 months ago 85
Git Question

GIT - cannot squash commits : fatal: Needed a single revision

I'm trying to squash my last 2 commits with git.
In this example I have created a branch from another branch called develop and I have 3 new commits, this is the git log :

commit a350cf6071db1bcaa2a37710a61508565a34d917
Author: tibbus
Date: Tue Sep 6 11:49:19 2016 +0200

commit message #3

commit 8c0384b995831e5a62b423721434005788b2eb63
Author: tibbus
Date: Tue Sep 6 11:49:01 2016 +0200

commit message #2

commit 6eab9df2df71196d62dab3c6caed9cd0ac6aeee5
Author: tibbus
Date: Tue Sep 6 11:48:41 2016 +0200

commit message #1
more commits from develop...

So I want to squash commit #3 and commit #2 into one single commit, I try :

git rebase -i HEAD˜2

and I get this error :

fatal: Needed a single revision
invalid upstream HEAD˜2

If I do :

git rebase -i develop

Works fine, but I do not want to squash all 3 commits, I want only the latest 2. I have read that this error appears when you don't have enough commits, but I definitely have ¯_(ツ)_/¯

Answer Source

You are using a wrong ~ symbol. ˜ in your command is the small tilde non-ASCII character, whereas you need the regular tilde ASCII symbol. Did you copy it from somewhere or the ~ on your keyboard inserts ˜?

Copy&paste the command from my answer and it should work without any problem:

git rebase -i HEAD~2