卡在git rebase中...如何重置

时间:2019-03-07 14:07:42

标签: git rebase

我正在经历git rebase的一部分,并且被卡住了。我不记得确切发生了什么,但是我正在使用UI并删除了一个已签出的分支,而且一切似乎一片空白。我重新启动并设法完成了一些其他工作,创建并提交到其他分支等,但是随后我注意到一个状态,说我仍在进行重新定位

如果我尝试

git rebase --skip
git rebase --continue
git rebase --abort

每项失败

error: could not read '.git/rebase-merge/head-name': No such file or directory

有没有办法让我回到稳定状态?我真的不介意与重新设置相关的内容,因此不会试图回到我仍然处于重新设置中间的位置。

编辑:

$ git status
On branch fix/SJW-01225
Your branch is up to date with 'core-v3/fix/SJW-01225'.

You are currently rebasing.
(all conflicts fixed: run "git rebase --continue")

Untracked files:
(use "git add <file>..." to include in what will be committed)

     [long list of untracked files]

nothing added to commit but untracked files present (use "git add" to track)

编辑1:

$ touch .git/rebase-merge/head-name

$ git rebase --abort
error: could not read '.git/rebase-merge/onto': No such file or directory

$ touch .git/rebase-merge/onto

$ git rebase --abort
error: could not get 'onto': ''

Thx

4 个答案:

答案 0 :(得分:7)

要摆脱损坏的git rebase,您可以执行以下操作

  1. 重置为已知状态。您可以了解从rebase开始git reflog的提交。

例如,reflog将为您提供以下内容。重新设置基准点是最后一个rebase (start)rebase -i (start)(如果您进行了交互式重新设置基准)。这里是HEAD@{1}

$ git reflog
f10ccfed (HEAD) HEAD@{0}: rebase : fast-forward
383aa038 (origin/master, origin/HEAD) HEAD@{1}: rebase (start): checkout HEAD~10
0600cf7e (origin/Files, master, Files) HEAD@{4}: checkout: moving from master to Files
0600cf7e (origin/Files, master, Files) HEAD@{5}: commit: fixes
f10ccfed (HEAD) HEAD@{6}: commit: refactoring

所以您需要的是:

    git checkout master # assuming you were on master
    git reset --hard HEAD@{1}
  1. 删除rebase-merge文件夹
    rm -rf .git/rebase-merge

答案 1 :(得分:0)

我莫名其妙地使我的仓库进入了相同的状态。在我的情况下,没有.git/rebase-merge目录,但是我确实找到了rebase-apply目录。除了进行中的重新设置基准之外,git status很干净,因此,要摆脱怪异的错误重新设置基准状态,我唯一需要做的就是运行:

rm -rf .git/rebase-apply/

答案 2 :(得分:0)

我遇到了类似的问题:

$ git status
On branch master
You are currently rebasing.
  (all conflicts fixed: run "git rebase --continue")
nothing to commit, working tree clean
$ git rebase --abort
error: could not read '.git/rebase-merge/head-name': No such file or directory
$ git rebase --skip
error: could not read '.git/rebase-merge/head-name': No such file or directory
$ git rebase --continue
error: could not read '.git/rebase-merge/head-name': No such file or directory

因此,我尝试启动一个新的基准,并且得到了这个线索(顺便说一句,我第一次看到Git以第一人称引用自己):

$ git rebase -i HEAD~1
fatal: It seems that there is already a rebase-merge directory, and
I wonder if you are in the middle of another rebase.  If that is the
case, please try
    git rebase (--continue | --abort | --skip)
If that is not the case, please
    rm -fr ".git/rebase-merge"
and run me again.  I am stopping in case you still have something
valuable there.
$ rm -fr ".git/rebase-merge"
$ git status
On branch master
nothing to commit, working tree clean
$ git push origin master
Everything up-to-date

因此,在我的情况下,该问题是通过rm -fr ".git/rebase-merge"强制递归删除Git的rebase-merge目录来解决的。

答案 3 :(得分:0)

遇到了类似的问题,其中--abort无效

$ git rebase master
error: could not write index
fatal: Could not detach HEAD
First, rewinding head to replay your work on top of it...

,使用找不到回购的任何问题

$ git status
On branch XXX
nothing to commit, working tree clean
$ ls .git/r*
#Nothing of interest

在我通过清理修复的问题上,即发出以下命令(如果您未进行更改,则具有破坏性)命令

git clean -xfd