致命:无法打开文件 .git/rebase-merge/done 进行阅读:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38793538/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:27:47  来源:igfitidea点击:

fatal: Could not open file .git/rebase-merge/done for reading: No such file or directory

gitgithub

提问by Andrea

I was going to do a rebase to delete my last commit but I didn't want to finish so I exited. (I realize this probably was not the best way to go about it, but it's done) I guess I did it wrong because I am getting the error: fatal: Could not open file .git/rebase-merge/done for reading: No such file or directoryevery time I run git status. How do I get rid of this error so I can continue making commits? Can I just delete the file? If I can delete it, how would I do that?

我打算做一个 rebase 来删除我的最后一次提交,但我不想完成所以我退出了。(我意识到这可能不是最好的方法,但它已经完成了)我想我做错了,因为我收到错误:fatal: Could not open file .git/rebase-merge/done for reading: No such file or directory每次运行git status. 我如何摆脱这个错误,以便我可以继续提交?我可以删除文件吗?如果我可以删除它,我该怎么做?

回答by DavidN

Before you try the following, make sure you stashor commitany uncommitted changes first, or you will lose them irrevocably.

在您尝试以下操作之前,请先确保您stashcommit任何未提交的更改,否则您将不可撤销地丢失它们。

Then try to do a git rebase --abort.

然后尝试做一个git rebase --abort.

回答by Stefano

Stash or commit didn't work for me, I just created the files that git was complaining about until it worked!

Stash 或 commit 对我不起作用,我只是创建了 git 抱怨的文件,直到它起作用为止!

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

echo "master" > .git/rebase-apply/head-name

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

$ echo "develop" > .git/rebase-apply/onto

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

$ echo "develop" > .git/rebase-apply/head

After which git rebase --abortworked. The branch names you are putting in those files needs to exists, and in my case I didn't care about my local changes, but obviously be careful with this if you do.

之后git rebase --abort工作。您放入这些文件中的分支名称需要存在,在我的情况下,我不关心我的本地更改,但如果您这样做,显然要小心。

回答by Dimitris Baltas

DavidN's solution to abort the rebase is greatas long as you don't have any unstagedchanges since the last rebase going south!

DavidN 中止 rebase 的解决方案很棒,只要自上次 rebase 向南以来您没有任何未分阶段的更改!

If you wrote code after the rebase attempt, ignoring the could not open file .git/rebase-merge/donemessage,

如果您在 rebase 尝试后编写代码,忽略could not open file .git/rebase-merge/done消息,

then your best bet is to do

那么你最好的办法就是做

git stash

to save your local changes and only then abort the rebase.

保存您的本地更改,然后才中止变基。

I am sure this is one of those stackoverflow questions, where people who are eager to solve their problem without considering the implications, will just run the abort command and regret it soon after.

我确信这是 stackoverflow 问题之一,那些急于解决问题而不考虑影响的人只会运行 abort 命令并很快后悔。