fatal: Needed a single revision

后端 未结 1 742
礼貌的吻别
礼貌的吻别 2021-01-15 06:42

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         


        
相关标签:
1条回答
  • 2021-01-15 07:29

    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).

    0 讨论(0)
提交回复
热议问题