git 从失败的变基中恢复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4660521/
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
Recovering from a failed rebase
提问by davidtbernal
I'm using git svn
to get some git goodness with the company-mandated svn server. I just had a rebase go horribly awry, and I"m trying to figure out the best way to recover.
我正在使用git svn
公司授权的 svn 服务器来获得一些 git 优点。我刚刚重新设置了一个可怕的错误,我正在努力找出最好的恢复方法。
Here's what happened:
这是发生的事情:
To start with, I had this
---1 (master) \--B--C--D--E (feature/fix-widgets)
So then I did
git checkout master
and thengit svn rebase
on master to pull down those commits. I did not anticipate any conflicts between my feature branch and the master, because the changes were in a totally different folder. So at this point, I think I have this:---1--2--3--4 (master) \--B--C--D--E (feature/fix-widgets)
Where
1--2--3--4
are commits pulled in from svn.Next I do
git checkout feature/fix-widgets
and thengit rebase master
. There's immediately a conflict, and some things that don't add up, so I decide to slink away and look at things more carefully. I dogit rebase --abort
, hoping this will restore me to where I was before the rebase.I do
git rebase --abort
and receive the following message$ git rebase --abort error: git checkout-index: unable to create file somedir/somefile.cs (Permission denied) fatal: Could not reset index file to revision 'be44daa05be39f6dd0d602486a598b63b6bd2af7'.
Now I'm not sure what to do.
git status
shows that I'm onfeature/fix-widgets
, but I have a whole bunch of staged changed, and a large number of untracked files, which were previously committed. I'd be fine if I could get backE
.
首先,我有这个
---1 (master) \--B--C--D--E (feature/fix-widgets)
然后我做了
git checkout master
,然后git svn rebase
在 master 上拉下了这些提交。我没有预料到我的功能分支和主分支之间有任何冲突,因为更改位于完全不同的文件夹中。所以在这一点上,我想我有这个:---1--2--3--4 (master) \--B--C--D--E (feature/fix-widgets)
1--2--3--4
从 svn 中提取的提交在哪里。接下来我做
git checkout feature/fix-widgets
然后git rebase master
。马上就发生了冲突,有些事情并没有加起来,所以我决定偷偷溜走,仔细看看事情。我愿意git rebase --abort
,希望这能让我恢复到 rebase 之前的状态。我做了
git rebase --abort
并收到以下消息$ git rebase --abort error: git checkout-index: unable to create file somedir/somefile.cs (Permission denied) fatal: Could not reset index file to revision 'be44daa05be39f6dd0d602486a598b63b6bd2af7'.
现在我不知道该怎么办。
git status
显示我在feature/fix-widgets
,但我有一大堆暂存的更改,以及大量未跟踪的文件,这些文件以前已提交。如果我能回来就好了E
。
回答by VonC
You should have a look at ORIG_HEAD
你应该看看 ORIG_HEAD
ORIG_HEAD
is previous state ofHEAD
, set by commands that have possibly dangerous behavior, to be easy to revert them.
It is less useful now that Git has reflog:HEAD@{1}
is roughly equivalent toORIG_HEAD
(HEAD@{1}
is always last value ofHEAD
,ORIG_HEAD
is last value ofHEAD
before dangerous operation)
ORIG_HEAD
是 的先前状态HEAD
,由可能具有危险行为的命令设置,以便于恢复它们。
现在 Git 有 reflog 的用处不大:HEAD@{1}
大致相当于ORIG_HEAD
(HEAD@{1}
总是最后一个值HEAD
,ORIG_HEAD
是HEAD
危险操作之前的最后一个值)
So try this git reset
to get back to before any rebase:
因此,请尝试git reset
在任何 rebase 之前返回:
git reset --hard ORIG_HEAD