I am trying to squash the git commits with following command
$ git rebase -i HEAD~3
But after running above command I am facing following error:
fatal: invalid upstream 'HEAD~3'
CodePudding user response:
You get the invalid upstream <xxx>
message when <xxx>
doesn't match anything known to git.
In your case : if you are on a fresh branch with only 3 commits, HEAD~3
(the 3rd parent of current commit) does not exist, hence the message.
To squash commits together, you can use :
git reset --soft <sha of the first commit> # or : git reset --soft HEAD~2
git commit --amend
If you want to use git rebase
, there is a special --root
option to say "rebase the whole branch" :
git rebase -i --root