致命:需要进行一次修订 [英] fatal: Needed a single revision

查看:96
本文介绍了致命:需要进行一次修订的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的仓库有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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆