简体   繁体   English

git:我不小心将功能分支合并到master中,而不是进行合并

[英]git: I accidentally merged feature branch into master instead of develop

I'm using git and working with master/develop/feature branches. 我正在使用git并使用master / develop / feature分支。

The master only had the README file. 母版只有README文件。 And, unfortunately, I accidentally merged the feature branch I was working into the master instead the develop branch. 而且,不幸的是,我无意中将我正在使用的功能分支合并到了master分支中,而不是合并到了develop分支中。 And also removed the feature branch. 并且还删除了功能分支。

I know little about git and I'm confused about what to do. 我对git知之甚少,我对该怎么办感到困惑。 But I think the right thing is to merge the changes on the feature branch (already removed) into develop and revert the merge into the master. 但是我认为正确的做法是将特征分支(已删除)上的更改合并到开发中,然后将合并还原到母版中。 But how to do that if I already removed the feature branch? 但是,如果我已经删除了功能分支,该怎么办?

Note that I'm assuming here that you haven't push ed the results of the merge. 请注意,我在这里假设您尚未push合并结果。 If you have, this still can work, but would require a "force push" which in turn impacts everyone else using the repo (see "recovering from upstream rebase" in the git rebase docs; as that's essentially the situation it would create). 如果有的话,这仍然可以工作,但是需要“强制推送”,这反过来会影响使用该存储库的其他所有人(请参阅git rebase文档中的“从上游重新存储恢复”;因为这实际上就是它会造成的情况)。 But if you haven't, you don't need to worry about any of that. 但是,如果您没有,则无需担心任何这些。 So: 所以:

First thing is to recreate the feature branch. 首先是重新创建功能分支。 I'm assuming it only ever existed locally. 我假设它只在本地存在。 (If it had been pushed before the merge, you might be able to recover it from the remote; but either way the approach below will work.) So (如果它是在合并之前被推送的,您也许可以从远程恢复它;但是无论哪种方式,下面的方法都会起作用。)

git checkout master
git checkout -b feature
git reset --hard HEAD^2

Now the feature branch is restored to the merge commit's "second parent" - which should be where it was before the merge. 现在,功能分支已还原到合并提交的“第二父级”-应该在合并之前的位置。

Next you need to remove the merge from master . 接下来,您需要从master删除合并。

git checkout master
git reset --hard HEAD^

And that's it; 就是这样; you're ready to merge the feature into the development branch. 您已经准备好将功能部件合并到开发分支中。

First checkout master branch using git checkout master , and create a new branch called feature from master branch: 第一个使用git checkout master checkout master分支,并从master分支创建一个名为feature的新分支:

git checkout -b feature

Again checkout master branch, and run the following command: 再次检出master分支,并运行以下命令:

git log

This should give list of commits you have on master branch. 这应该列出您在master分支上的提交列表。 You need to scroll through commit list, to copy the commit id that you want to revert to. 您需要滚动查看提交列表,以复制要还原的提交ID。 Suppose that id is advcf456yhn8 , then you need to write the command: 假设id为advcf456yhn8 ,那么您需要编写以下命令:

git reset --hard advcf456yhn8

This will revert all changes & revert back to actual content at specific commit id. 这将还原所有更改,并以特定的提交ID还原为实际内容。

Now you have created a branch feature , which you can merge into develop . 现在,您已经创建了一个分支feature ,可以将其合并到develop Simply do git checkout develop & merge feature branch by using git merge feature . 只需使用git merge feature进行git checkout develop和合并feature分支。

Also by running the following command, you can get your entire commit history: 另外,通过运行以下命令,您可以获得完整的提交历史记录:

git reflog

Easy way of Getting back the master to previous commit : 使主服务器恢复到先前提交的简单方法:

  1. clone you master repository 克隆您的主存储库
  2. If you are using any GUI on git, Use option "revert" to select the particular commit ID 如果您在git上使用任何GUI,请使用选项“还原”来选择特定的提交ID
  3. Once reverted, Kindly commit and push to master. 恢复后,请提交并推送到主服务器。

CMD: CMD:

  1. git clone master git克隆大师
  2. git reset --hard HEAD^ git reset --hard HEAD ^
  3. git commit -m "" git commit -m“”
  4. git push git推

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

相关问题 无意中合并了大师进入开发和推动 - Accidentally merged master into develop and pushed 我将分支开发合并到主分支,但在主分支上,开发没有变化 - I merged branches develop into master but on master branch no changes from develop Git:master/develop/feature 分支合并提交 - Git: master / develop / feature branch merge commits pull而不是fetch - 意外地将远程master合并到本地分支 - pull instead of fetch - accidentally merged remote master into local branch 不知怎的,我的git develop分支被合并到我的主分支中 - Somehow my git develop branch got merged into my master branch GIT merge develop into feature branch -- 同一个分支被合并和恢复后 - GIT merge develop into feature branch -- after the same branch was merged and reverted git:我将master合并为development,现在呢? - git: I merged master into develop, now what? Git 在合并到功能分支时恢复主恢复提交 - Git revert in master reverting commits when merged into feature branch Git图形:将分支显示为线性,而不是显示为master的分支(我认为) - Git graph: develop branch shown as linear instead of as a diverged branch of master (that I think) 问题将Git Feature分支合并到“Beta”分支(在它已经合并到“Develop”分支之后) - Issue merging Git Feature branch into “Beta” branch (after it has already been merged to “Develop” branch)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM