致命:需要进行一次修订 [英] fatal: Needed a single revision
问题描述
我的仓库有3个提交.我想挤个.
My repo has 3 commits. I want to squash to one.
我运行git rebase -i HEAD~3
并收到此错误:
fatal: Needed a single revision
invalid upstream HEAD~3
我能够先运行git rebase -i HEAD~2
然后运行git push origin +master
,现在我有2次提交.
I was able to run git rebase -i HEAD~2
and then git push origin +master
and now I have 2 commits.
但是我为什么不能git rebase -i HEAD~3
?
推荐答案
HEAD~3
是当前提交的祖父母.但是由于只有3次提交,因此没有祖父母(第一个提交是当前提交的祖父母).
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).
您可以通过使用 git reset
后接 git 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
移动HEAD
现在指向第一个提交,但是工作树和索引(暂存的文件)与原始的HEAD
同步;现在已暂存了第一次提交和第三次提交之间的所有更改,等待提交.
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
更新当前提交(这是您运行git reset --soft HEAD~2
之后的第一次提交.)
git commit --amend
updates the current commit (it is the first commit after you run git reset --soft HEAD~2
).
这篇关于致命:需要进行一次修订的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!