[英]Somehow my git develop branch got merged into my master branch
I am using git-flow, but that's not important. 我正在使用git-flow,但这并不重要。 My master branch is production and my develop branch is for development.
我的主分支是生产,我的开发分支是开发。
This morning, my master branch (this is my production release) hadn't been touched for weeks (since my last release). 今天早上,我的主分支(这是我的产品发布)几周没有被触及(自我上次发布以来)。 Now, when I look at my master branch, it has all of my commits from my develop branch.
现在,当我查看我的主分支时,它包含了我的开发分支的所有提交。
I don't see a merge in the git log
so I am confused how I can get my master branch back to its boring self. 我没有在
git log
看到合并,所以我很困惑如何让我的主分支回到它无聊的自我。
How can I find this rouge merge to my master branch and reverse it without losing my development work? 如何找到这个rouge合并到我的主分支并反转它而不会丢失我的开发工作?
Edit: 编辑:
Does this provide enough information to know what happened? 这是否提供了足够的信息来了解发生了什么?
Here is the output of git reflog
: 这是
git reflog
的输出:
0fe067c HEAD@{0}: pull: Fast-forward
300ba32 HEAD@{1}: checkout: moving from develop to master
06f1dd9 HEAD@{2}: pull: Fast-forward
0fe067c HEAD@{3}: commit: Add back prefix.
815ffe8 HEAD@{4}: pull: Fast-forward
f4c3e23 HEAD@{5}: pull: Fast-forward
93d1037 HEAD@{6}: pull: Fast-forward
e027c53 HEAD@{7}: commit: Don't commit changes to Prefix
96e37a9 HEAD@{8}: commit: Update URLs based on current server
Well, if the merge has been fast-forwarded, it won't create a merge commit which is probably what happened. 好吧,如果合并已经快速转发,它将不会创建合并提交,这可能是发生的事情。
So, from there, where do we go ? 所以,从那里,我们去哪里?
Well, if you have a remote still pointing to the good commit, you can reset your local branch pretty easily: 好吧,如果你有一个指向良好提交的遥控器,你可以很容易地重置你的本地分支:
git reset --hard origin/master
(where remote/branch
) git reset --hard origin/master
(其中remote/branch
)
Else, it's a little bit more complicated, but still: you can filter your reflog to only log master information: 否则,它有点复杂,但仍然:您可以过滤您的reflog以仅记录主信息:
git reflog show master
And if the logged info make sense, then you can reset: 如果记录的信息有意义,那么您可以重置:
git reset --hard master@{1}
Note that --hard
will discard all local change made to the working tree, if that's a trouble, use --keep
. 请注意
--hard
将丢弃对工作树所做的所有本地更改,如果这是一个麻烦,请使用--keep
。
Did you tag your production branch when you released? 你发布时是否标记了生产分支?
Do you have any idea of the sha1 of the last release? 你对上一版的sha1有什么看法吗?
I like Simon Boudrias's answer but it could be as simple as locating the commit you want using git log
and resetting the branch to that commit git reset --hard <sha1>
. 我喜欢Simon Boudrias的答案,但它可以像使用
git log
定位你想要的提交并将分支重置为提交git reset --hard <sha1>
。
Note: You might want to reset without the --hard part first to make sure it takes you to the point you want without losing information. 注意:您可能希望在没有--hard部分的情况下重置,以确保它能够将您带到您想要的位置而不会丢失信息。
git co production
git log # find the sha1
git reset <sha1> # to check if this is the point you want
git co production
git reset --hard <sha1>
Since you are not deleting any commit from "development" you are not losing commits (as long as no one had been developing in production directly). 由于您没有从“开发”中删除任何提交,因此您不会丢失提交(只要没有人直接在生产中开发)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.