卡在一个git rebase里…如何重置

zfciruhq  于 2023-08-01  发布在  Git
关注(0)|答案(5)|浏览(205)

我正在通过git rebase的一部分,我卡住了。我不记得发生了什么,但我使用了一个UI,删除了一个 checkout 的分支,一切似乎只是空白。我重新启动并设法做了一些其他的工作,创建和提交到其他分支等,但后来我注意到一个状态说我仍然在一个重基的中间
如果我尝试

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

字符串
每一个都失败

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


有没有办法让我回到稳定的状态?我真的不介意什么是rebase相关,所以我不试图回到点,我仍然在rebase的中间。
编辑:

$ 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

dw1jzc5e

dw1jzc5e1#

要从损坏的git rebase中逃脱,可以执行以下操作
1.重置为已知状态。你可以找出你从哪个提交开始你的rebasegit 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

p8h8hvxi

p8h8hvxi2#

我不知怎么的把我的回购变成了同样的状态。在我的例子中,没有.git/rebase-merge目录,但我找到了rebase-apply目录。除了正在进行的rebase,git status是干净的,所以我唯一需要做的事情就是运行,以摆脱奇怪的坏rebase状态:

rm -rf .git/rebase-apply/

字符串

9rbhqvlz

9rbhqvlz3#

git rebase --quit为我工作。

suzh9iv8

suzh9iv84#

我遇到了类似的问题:

$ 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目录来解决的。

wqlqzqxt

wqlqzqxt5#

遇到类似的问题,--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

相关问题