忘记了“git rebase --continue”并做了“git commit”。怎么修?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6457044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forgot "git rebase --continue" and did "git commit". How to fix?
提问by Abhilash
I was rebasing code in git, I got some merge conflicts. I resolved the conflicts and did:
我在 git 中重新定义代码,我遇到了一些合并冲突。我解决了冲突并做了:
git add
At this point I forgot to do:
在这一点上我忘了做:
git rebase --continue
I continued coding and did:
我继续编码并做了:
git commit
for the changes. Now I am on "no branch"
and can't do:
对于变化。现在我在"no branch"
但不能做:
git rebase --continue
How do I fix this?
我该如何解决?
采纳答案by MatrixFrog
edit: Look at the answer below as well to see if that's an easier solution for you. https://stackoverflow.com/a/12163247/493106
编辑:也看看下面的答案,看看这对你来说是否是一个更简单的解决方案。 https://stackoverflow.com/a/12163247/493106
I'd have to try it out, but I think this is what I would do:
我必须尝试一下,但我认为这就是我要做的:
- Tag your latest commit (or just write down its SHA1 somewhere so you don't lose it):
git tag temp
git rebase --abort
- Do the rebase again. You'll have to resolve the merge again. :(
git rebase --continue
git cherry-pick temp
- 标记你的最新提交(或者只是在某处写下它的 SHA1,这样你就不会丢失它):
git tag temp
git rebase --abort
- 再做一次rebase。您必须再次解决合并问题。:(
git rebase --continue
git cherry-pick temp
The problem with this is that your temp
commit probably contains both the resolution of the merge, and the new code. So it could be tricky but I would try it and see if it works.
问题在于您的temp
提交可能包含合并的分辨率和新代码。所以这可能很棘手,但我会尝试一下,看看它是否有效。
回答by kirikaza
Just do git reset --soft HEAD^
. It moves the HEAD pointer to its parent but keeps the work tree and adds the merge change to the index. So you can continue rebasing with git rebase --continue
as before.
就做git reset --soft HEAD^
。它将 HEAD 指针移动到其父级,但保留工作树并将合并更改添加到索引。所以你可以git rebase --continue
像以前一样继续变基。
回答by Louis Durand
I got the same problem, and to make it worse, I was rebasing three commits, and after solving conflicts on the second commit, I "committed" instead of "rebase --continue".
我遇到了同样的问题,更糟糕的是,我重新设置了三个提交,在解决第二个提交的冲突后,我“提交”而不是“rebase --continue”。
As a result I had this git reflog
结果我有了这个git reflog
When I applied kirikaza's solution, I just reverted the third commit, and not the second one, which was problematic..
当我应用 kirikaza 的解决方案时,我只是恢复了第三次提交,而不是第二次提交,这是有问题的..
As you can see, the rebase starts by a checkout from the remotes/origin/master branch and then applies my three commits that appear as the three previous operation (before the checkout) in the reflog.
如您所见,rebase 从 remotes/origin/master 分支的检出开始,然后应用我的三个提交,这些提交显示为 reflog 中的前三个操作(检出之前)。
Then, if you want to restart from a clean base, before the rebase, you can simply reset hard to the hash just before the checkout of the rebase operation. In my case (see the picture):
然后,如果你想从一个干净的基础重新启动,在 rebase 之前,你可以在 rebase 操作检出之前简单地将 hard 重置为 hash。就我而言(见图):
git reset --hard 859ed3c
Then you can start a new git rebase
.
然后你可以开始一个新的git rebase
.
回答by remnant
I had git rebased, fixed conflicts, git added file with conflicts, and (mistakenly) committed.
我有 git rebased,修复了冲突,git 添加了冲突的文件,并且(错误地)提交了。
I tried the git reset --soft HEAD^
and git reset --hard
solutions given, but neither worked for me.
我试过git reset --soft HEAD^
和git reset --hard
解决方案给出的,但也对我来说有效。
However, just git rebase --abort
worked: it took me back to before the start of the rebase with a clean working tree.
然而,刚刚git rebase --abort
奏效:它让我回到了重新开始之前用干净的工作树。