Git - 如何修复“损坏的”交互式变基?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3685001/
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
Git - How to fix "corrupted" interactive rebase?
提问by Mikael Koskinen
I managed to create a little mess in my local git repository. I was trying to fix a broken commit by using the following instructions. Before running the "git commit --amend" (and after the git rebase --interactive) I decided that my changes were incorrect and so I executed "git reset HEAD --hard". Not a good idea, I tell you.
我设法在我的本地 git 存储库中创建了一些混乱。我试图通过使用以下说明修复损坏的提交。在运行“git commit --amend”之前(以及在 git rebase --interactive 之后),我认为我的更改不正确,因此我执行了“git reset HEAD --hard”。不是个好主意,我告诉你。
Now the interactive rebase seems to be "stuck". Git shows the current branch as (|REBASE-m). Every command (cd .., ls, git rebase...) inside my repository gives the following error:
现在交互式 rebase 似乎“卡住了”。Git 将当前分支显示为 (|REBASE-m)。我的存储库中的每个命令(cd ..、ls、git rebase...)都会出现以下错误:
cat: .git/rebase-merge/head-name: No such file or directory
cat: .git/rebase-merge/head-name: 没有那个文件或目录
Here's how git rebase --abort looks like:
这是 git rebase --abort 的样子:
$ git rebase --abort
cat: c:/_work/project/src/git/.git/rebase-merge/quiet: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/head-name: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/orig-head: No such file or directory
HEAD is now at 4c737fb Revert "Modified file names"
rm: cannot remove `c:/_work/project/src/git/.git/rebase-merge/done': Permission denied
rm: cannot remove directory `c:/_work/project/src/git/.git/rebase-merge': Directory
not empty
cat: .git/rebase-merge/head-name: No such file or directory
Here's the result of git rebase --continue:
这是 git rebase --continue 的结果:
$ git rebase --continue
cat: c:/_work/project/src/git/.git/rebase-merge/prev_head: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/end: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/msgnum: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/onto: No such file or directory
cat: c:/_work/project/src/git/.git/rebase-merge/quiet: No such file or directory
prev_head must be defined
cat: .git/rebase-merge/head-name: No such file or directory
Any ideas? I would like to reset the situation back to the state it was before I started my well-thought rebase operation.
有任何想法吗?我想将情况重置回我开始深思熟虑的 rebase 操作之前的状态。
Here's how git log --oneline shows the situation:
以下是 git log --oneline 显示情况的方式:
4c737fb Revert "Modified file names"
247ac02 Modified file names
33141e6 Message modifications
10a4a04 Modified db script
And this is fine.
这很好。
I'm using msysgit v1.7.0.2.
我正在使用 msysgit v1.7.0.2。
采纳答案by Martin Owen
It looks like Git tried to remove the .git/rebase-merge
directory but wasn't able to remove it completely. Have you tried copying that folder away? Also copy away the .git/rebase-apply
folder if that is present.
看起来 Git 试图删除该.git/rebase-merge
目录,但无法完全删除它。你试过把那个文件夹复制掉吗?.git/rebase-apply
如果存在该文件夹,也将其复制掉。
回答by Laura Slocum
I got stuck in this. I created the head-name file, and then I ran into another error saying it couldn't find the onto file, so I created that file. Then I got anothererror saying could not read '.git/rebase-apply/onto': No such file or directory.
我陷入了困境。我创建了 head-name 文件,然后我遇到了另一个错误,说它找不到 on 文件,所以我创建了那个文件。然后我收到另一个错误,说无法读取“.git/rebase-apply/onto”:没有这样的文件或目录。
SoI looked at the git documentationfor rebasing and found another command called git rebase --quit
. This set me back on my branch with no changes, and I could start my rebase over again, good as new.
所以我查看了用于 rebase的 git文档,发现了另一个名为git rebase --quit
. 这让我回到了我的分支,没有任何变化,我可以重新开始我的 rebase,就像新的一样。
回答by user584317
I had a similar problem due to a zombie vim.exe process.
Killing it in Task Manager, followed by a git rebase --abort
fixed it.
由于僵尸 vim.exe 进程,我遇到了类似的问题。在任务管理器中杀死它,然后git rebase --abort
修复它。
回答by Ruth
Thanks @Laura Slocum for your answer
感谢@Laura Slocum 的回答
I messed things up while rebasing and got a detached HEAD with an
我在变基时把事情搞砸了,得到了一个分离的 HEAD
error: could not read orig-head
that prevented me from finishing the rebasing.
这使我无法完成变基。
The detached HEAD seem to contain precisely my correct rebase desired state, so I ran
分离的 HEAD 似乎正好包含我正确的 rebase 所需状态,所以我跑了
rebase --quit
and after that I checked out a new temp branch to bind it to the detached head.
之后,我检查了一个新的临时分支以将其绑定到分离的头部。
By comparing it with the branch I wanted to rebase, I can see the new temp branch is exactly in the state I wanted to reach. Thanks
通过将它与我想要变基的分支进行比较,我可以看到新的临时分支正好处于我想要达到的状态。谢谢
回答by Praveen Hiremath
Had same problem in Eclipse. Could not Rebase=>abort from Eclipse.
在 Eclipse 中有同样的问题。无法从 Eclipse 变基=> 中止。
Executing git rebase --abortfrom Git Bash Worked for me.
从 Git Bash执行git rebase --abort对我有用。
回答by Darren Yeats
On Windows, if you are unwilling or unable to restart the machine see below.
在 Windows 上,如果您不愿意或无法重新启动机器,请参见下文。
Install Process Explorer: https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx
安装进程资源管理器:https: //technet.microsoft.com/en-us/sysinternals/bb896653.aspx
In Process Explorer, Find > File Handle or DLL ...
在进程资源管理器中,查找 > 文件句柄或 DLL ...
Type in the file name mentioned in the error (for my error it was 'git-rebase-todo' but in the question above, 'done').
输入错误中提到的文件名(对于我的错误,它是“git-rebase-todo”,但在上面的问题中,“完成”)。
Process Explorer will highlight the process holding a lock on the file (for me it was 'grep').
Process Explorer 将突出显示持有文件锁的进程(对我来说它是“grep”)。
Kill the process and you will be able to abort the git action in the standard way.
终止该进程,您将能够以标准方式中止 git 操作。
回答by Tehila Dabush
Create a file with this name:
用这个名字创建一个文件:
touch .git/rebase-merge/head-name
and than use git rebase
然后使用 git rebase
回答by Dariusz
In my case eighter git rebase --abort
and git rebase --continue
was throwing:
在我的情况eightergit rebase --abort
和git rebase --continue
被扔:
error: could not read '.git/rebase-apply/head-name': No such file or directory
错误:无法读取“.git/rebase-apply/head-name”:没有这样的文件或目录
I managed to fix this issue by manually removing: .git\rebase-apply
directory.
我设法通过手动删除:.git\rebase-apply
目录来解决此问题。
回答by meridius
In my case it was because I had opened SmartGit's Log in the respective Git project and Total Commander in the respective project directory. When I closed both I was able to rebase without any problem.
就我而言,这是因为我在各自的 Git 项目中打开了 SmartGit 的日志,并在各自的项目目录中打开了 Total Commander。当我关闭两者时,我能够毫无问题地重新定位。
The more I think about it, the more I suspect Total Commander, i.e. Windows having a lock on opened directory the git rebase was trying to something with.
我想得越多,我就越怀疑 Total Commander,即 Windows 锁定了 git rebase 试图使用的打开目录。
Friendly advice: When you try to fix something, always do one change at a time. ;)
友好的建议:当你试图修复某事时,总是一次做一个改变。;)
回答by Spongman
I'm using git version 2.19.2.windows.1
.
我正在使用git version 2.19.2.windows.1
.
the only thing that worked for me was to remove the .git/rebase-apply/
directory and do a git reset --hard
.
唯一对我有用的是删除.git/rebase-apply/
目录并执行git reset --hard
.