简体   繁体   English

Git Undo合并删除了未提交的更改

[英]Git Undo merge that removed uncommitted changes

Ok, 好,

so the entire point of source control is to track changes so mess ups and deletions, or bad feature paths can be rectified - however we may need to do so. 因此,源代码管理的整个重点是跟踪更改,以便进行混乱和删除,或者可以纠正不良的功能路径-但是我们可能需要这样做。

Git is awesome for that. 对此,Git很棒。 But recently something happened that blows my mind. 但是最近发生了一件令我震惊的事情。

I have master, develop and Phase3 branches. 我有master,develop和Phase3分支。 Master and develop are remote branches where Phase3 was local. Master和development是Phase3在本地的远程分支机构。 Develop recently was branched to a Release branch for testing. Develop最近分支到Release分支进行测试。 This branch was later merged back into master when our release went to production. 当我们的发行版投入生产时,该分支后来又合并回了master。
I am sitting here realizing that i need to merge master back into develop to maintain the commit history, and noted that Phase3 should probably also have the latest branch merged in. 我坐在这里意识到我需要将master合并回development来维护提交历史,并指出Phase3应该也应该合并最新的分支。
this is where it all went south. 这就是一切的南方。 I went to merge master into Phase3 and it destroyed ALL of my current changes. 我去合并master到Phase3,它破坏了我所有的当前更改。
It didn't ask for a merge request. 它没有要求合并请求。 It didn't even say "You might want to commit or stash your changes to current documents". 它甚至没有说“您可能要提交或存储对当前文档的更改”。 It just overwrote them!!!! 它只是覆盖了他们!!!

I mean, I can't even check out alternate branches of a repository without Git warning me of possible data loss, but a merge can just overwrite these changes with nary a hint? 我的意思是,如果没有Git提醒我可能丢失数据,我什至无法签出存储库的其他分支,但是合并可以只用一个提示覆盖这些更改吗? WTF? WTF?

A) is there a way to tell the repository to UNDO this? A)有什么方法可以告知存储库此操作吗? (unlikely) B) is there a way to tell GIT to NEVER merge when there are active changes? (不太可能)B)有什么方法可以告诉GIT在活动更改时永远不要合并? Basically to get the same warning on a git merge as i get on a git checkout. 基本上在git merge上得到和我在git checkout上一样的警告。

Thanks Jaeden "Sifo Dyas" al'Raec Ruiner 感谢Jaeden“ Sifo Dyas” al'Raec Ruiner

You need git reflog . 您需要git reflog

Look at the output of git reflog very carefully. 仔细查看git reflog的输出。 Identify the state you were at before you ran the merge/rebase/whatever. 在运行合并/变基/任何操作之前,请先确定您所处的状态。 Then do a 然后做一个

git reset --hard HEAD@{WHATEVER NUMBER FIND FROM THE REFLOG}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM