撤消git rebase [英] Undoing a git rebase

查看:133
本文介绍了撤消git rebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人知道如何轻松撤销git rebase?



想到的唯一方法是手动进行:




  • git检出两个分支的提交父母

  • 然后从那里创建一个临时分支
  • cherry手动提交所有提交

  • 替换由手动创建的分支重新分配的分支



在我目前的情况下,这是可行的,因为我可以很容易地发现两个分支的提交(一个是我的东西,另一个是我的同事的东西)。

然而,我的方法让我觉得不够理想,并且容易出错(假设我刚刚用我自己的分支中的2个重新组合)。

任何想法?

p>

澄清:我正在谈论重新发布一系列提交的重新发布。不仅仅是一个。

解决方案

最简单的方法是找到分支的头部提交,因为它刚好在分割开始之前在推荐日志 ...

  git reflog 

并将当前分支重置为它(通常需要在重置 - hard 选项之前绝对确定)。



假设旧在ref日志中提交 HEAD @ {5}

  git重设--hard HEAD @ {5} 

在Windows中,您可能需要引用参考:

  git reset --hardHEAD @ {5}

$ b

您可以通过执行 git log HEAD @ {5}来检查候选老版本的历史记录 code>( Windows: git logHEAD @ {5})。

如果您没有禁用每个分支r eflogs你应该能够简单地执行 git reflog branchname @ {1} 作为rebase分离分支头部,然后重新连接到最后的头部。我会再仔细检查一下,不过我最近还没有核实过。



默认情况下,所有reflog都会在非裸仓库中激活:

  [core] 
logAllRefUpdates = true


Does anybody know how to easily undo a git rebase?

The only way that comes to mind is to go at it manually:

  • git checkout the commit parent to both of the branches
  • then create a temp branch from there
  • cherry-pick all commits by hand
  • replace the branch in which I rebased by the manually-created branch

In my current situation this is gonna work because I can easily spot commits from both branches (one was my stuff, the other was my colleague's stuff).

However my approach strikes me as suboptimal and error-prone (let's say I had just rebased with 2 of my own branches).

Any ideas?

Clarification: I'm talking about a rebase during which a bunch of commits were replayed. Not only one.

解决方案

The easiest way would be to find the head commit of the branch as it was immediately before the rebase started in the reflog...

git reflog

and to reset the current branch to it (with the usual caveats about being absolutely sure before reseting with the --hard option).

Suppose the old commit was HEAD@{5} in the ref log:

git reset --hard HEAD@{5}

In Windows, you may need to quote the reference:

git reset --hard "HEAD@{5}"

You can check the history of the candidate old head by just doing a git log HEAD@{5} (Windows: git log "HEAD@{5}").

If you've not disabled per branch reflogs you should be able to simply do git reflog branchname@{1} as a rebase detaches the branch head before reattaching to the final head. I would double check this, though as I haven't verified this recently.

Per default, all reflogs are activated for non-bare repositories:

[core]
    logAllRefUpdates = true

这篇关于撤消git rebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆