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

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

Recovering from a failed rebase

gitgit-svnrebase

提问by davidtbernal

I'm using git svnto 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:

这是发生的事情:

  1. To start with, I had this

    ---1 (master)
        \--B--C--D--E (feature/fix-widgets)
    
  2. So then I did git checkout masterand then git svn rebaseon 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--4are commits pulled in from svn.

  3. Next I do git checkout feature/fix-widgetsand then git 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 do git rebase --abort, hoping this will restore me to where I was before the rebase.

  4. I do git rebase --abortand 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'.
    
  5. Now I'm not sure what to do. git statusshows that I'm on feature/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 back E.

  1. 首先,我有这个

    ---1 (master)
        \--B--C--D--E (feature/fix-widgets)
    
  2. 然后我做了git checkout master,然后git svn rebase在 master 上拉下了这些提交。我没有预料到我的功能分支和主分支之间有任何冲突,因为更改位于完全不同的文件夹中。所以在这一点上,我想我有这个:

    ---1--2--3--4 (master)
        \--B--C--D--E (feature/fix-widgets)
    

    1--2--3--4从 svn 中提取的提交在哪里。

  3. 接下来我做git checkout feature/fix-widgets然后git rebase master。马上就发生了冲突,有些事情并没有加起来,所以我决定偷偷溜走,仔细看看事情。我愿意git rebase --abort,希望这能让我恢复到 rebase 之前的状态。

  4. 我做了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'.
    
  5. 现在我不知道该怎么办。git status显示我在feature/fix-widgets,但我有一大堆暂存的更改,以及大量未跟踪的文件,这些文件以前已提交。如果我能回来就好了E

回答by VonC

You should have a look at ORIG_HEAD

你应该看看 ORIG_HEAD

ORIG_HEADis previous state of HEAD, 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 to ORIG_HEAD(HEAD@{1}is always last value of HEAD, ORIG_HEADis last value of HEADbefore dangerous operation)

ORIG_HEAD是 的先前状态HEAD,由可能具有危险行为的命令设置,以便于恢复它们。
现在 Git 有 reflog 的用处不大:HEAD@{1}大致相当于ORIG_HEADHEAD@{1}总是最后一个值HEADORIG_HEADHEAD危险操作之前的最后一个值)

So try this git resetto get back to before any rebase:

因此,请尝试git reset在任何 rebase 之前返回:

git reset --hard ORIG_HEAD