简体   繁体   English

不知怎的,我的git develop分支被合并到我的主分支中

[英]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.

相关问题 不知何故从我的git local分支走了 - got out of my git local branch somehow Git,如何使我的开发镜像/克隆我的主分支? - Git, How to make my develop mirror/clone my master branch? 使用 Git,在我的代码提交合并到 master 分支后,我是否要删除我的远程分支,再次克隆 master 并检查下一个分支? - With Git, after my code commits are merged to the master branch, do I delete my remote branch, clone master again and checkout the next branch? 如何停止与开发分支合并的分支与主分支合并? - How to stop a branch merged with develop branch to be merged with master branch? git:我不小心将功能分支合并到master中,而不是进行合并 - git: I accidentally merged feature branch into master instead of develop 在git中重新创建我的master分支 - recreate my master branch in git 如何在BitBucket / Git中的develop分支中创建master分支? - How can I create a master branch from my develop branch in BitBucket/Git? 我将分支开发合并到主分支,但在主分支上,开发没有变化 - I merged branches develop into master but on master branch no changes from develop 将我的分支合并到已经与 master 的更改合并的 master - Merging my branch to master which is already merged with changes from master 如何从另一个分支(开发)更新我的工作 Git 分支? - How to update my working Git branch from another branch (develop)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM