My repo has 3 commits. I want to squash to one.
I ran git rebase -i HEAD~3
and got this error:
fatal: Needed a single revision
invalid u
HEAD~3
is the grand-grand-parent of the current commit. But since there are only 3 commits, there is no grand-grand-parent (the first commit is the grand-parent of the current commit).
You can achieve the desired outcome by using git reset followed by git commit:
git reset --soft HEAD~2
git commit --amend
git reset --soft moves the HEAD
to the provided commit but doesn't change the work tree and the index. The HEAD
now points to the first commit but the working tree and the index (the staged files) are synchronized with the original HEAD
; all the changes between the first commit and the third commit are now staged, waiting to be committed.
git commit --amend updates the current commit (it is the first commit after you run git reset --soft HEAD~2
).