自 rebase 开始以来,中止了旧的 git rebase 并丢失了提交

发布于 2024-08-29 12:46:16 字数 319 浏览 2 评论 0原文

大约一周前,我在尝试清理我的存储库时重新调整了一些提交,显然我实际上并没有完成它。今天,一周和几次提交之后,我去 rebase 重新排序了今天的一些提交,它告诉我我已经处于 rebase 中间了。

这应该是复制我的存储库的提示,以防万一。但我没有……相反,我运行了 git rebase --abort ,这在当时听起来是正确的。嗯,那是不对的。它中止了一周前的变基并将 master 的 HEAD 重置为旧的。

我还有其他几个相当新的分支,并且我已经多次推送到远程,但最近的更改似乎永远消失了。我不具备适当水平的 git-fu 来知道是否有任何方法可以恢复我的更改。

我完蛋了吗?

About a week ago, I was rebasing some commits while trying to clean up my repository, and apparently I didn't actually finish it. Today, a week and several commits later, I went to rebase to reorder a few commits from today, and it told me I was already in the middle of a rebase.

That should have been a cue to copy my repo just in case. But I did not... Instead, I ran git rebase --abort which sounded right at the time. Well, that was not right. It aborted the rebase from a week ago and reset master's HEAD to the old one.

I've got several other branches that are fairly recent, and I've pushed to remote several times, but the most recent changes appear to be gone forever. I don't possess the appropriate level of git-fu to know if there's any way to recover my changes.

Am I screwed?

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

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

发布评论

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

评论(2

面如桃花 2024-09-05 12:46:16

检查 git reflog 。在几乎所有情况下,您都可以使用这些提交哈希值作为参考来回溯过去。

我还会将 git repo 目录物理复制到其他地方,作为进行初步测试的地方,看看什么会起作用,这样你就可以搞乱你想要的任何东西,而不会丢失未跟踪的文件或让事情进入你可以的状态t 回来。

Check git reflog. You can walk back in time using those commit hashes as a reference in almost all cases.

I'd also physically copy the git repo directory elsewhere as a place to do preliminary testing to see what will work, that way you can mess with whatever you want without losing untracked files or getting things into a state that you can't come back from.

未央 2024-09-05 12:46:16

您应该能够使用 git reflog

然后,您将能够将当前分支重置为那些 SHA1

# Suppose the old commit was HEAD@{2} in the ref log
git reset --hard HEAD@{2}

这有点像“撤消git reset --hard HEAD~1”。

另请参阅“使用 Git 恢复丢失提交的图解指南",了解其他恢复示例。

You should be able to get the SHA1 of your most recent commits (that disappeared after the git rebase --abort) with a git reflog.

You will be able then to reset your current branch to those SHA1

# Suppose the old commit was HEAD@{2} in the ref log
git reset --hard HEAD@{2}

It is a bit like "Undoing a git reset --hard HEAD~1".

See also the "illustrated guide to recovering lost commits with Git", for other examples of recovery.

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