0

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'

Sudhakar Lahane
  • 137
  • 1
  • 2
  • 12
  • What is the output of `git log --decorate --oneline --graph`? (See also https://stackoverflow.com/questions/1057564/pretty-git-branch-graphs) – torek Nov 05 '21 at 08:07

1 Answers1

1

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
LeGEC
  • 46,477
  • 5
  • 57
  • 104