从失败的变基中恢复

发布于 2024-10-11 19:08:21 字数 1037 浏览 4 评论 0原文

我正在使用 git svn 来通过公司指定的 svn 服务器获得一些 git 的好处。我刚刚有一个变基严重错误,我正在尝试找出恢复的最佳方法。

发生的事情是这样的:

  1. 首先,我有这个

    <前><代码>---1(主) \--B--C--D--E(功能/修复小部件)
  2. 然后我做了 git checkout master ,然后在 master 上执行 git svn rebase 来拉下这些承诺。我没有预料到我的功能分支和主分支之间会发生任何冲突,因为更改位于完全不同的文件夹中。所以在这一点上,我想我有这个:

    <前><代码>---1--2--3--4(主) \--B--C--D--E(功能/修复小部件)

    其中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
      错误:git checkout-index:无法创建文件 somedir/somefile.cs (权限被拒绝)
      致命:无法将索引文件重置为修订版“be44daa05be39f6dd0d602486a598b63b6bd2af7”。
    
  5. 现在我不知道该怎么做。 git status 显示我正在使用 feature/fix-widgets,但我有一大堆暂存的更改,以及大量未跟踪的文件,这些文件是之前提交的。如果我能返回 E 就好了。

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.

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 master and then git 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.

  3. Next I do git checkout feature/fix-widgets and 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 --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'.
    
  5. Now I'm not sure what to do. git status shows 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

离鸿 2024-10-18 19:08:21

您应该查看ORIG_HEAD

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

所以试试这个 git reset 返回到任何 rebase 之前:

git reset --hard ORIG_HEAD   

You should have a look at ORIG_HEAD

ORIG_HEAD is 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_HEAD is last value of HEAD before dangerous operation)

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

git reset --hard ORIG_HEAD   
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文