如何补救意外地提交到主分支而不是我的功能分支 [英] How to remedy for accidently making a commit into the master branch instead of my feature branch

查看:174
本文介绍了如何补救意外地提交到主分支而不是我的功能分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在本地,我忘了从主分支创建一个功能分支,然后将更改提交到主分支。



如何更正错误,以便将提交从主分支中删除,并且变成新的功能分支?



谢谢。 git checkout master
git checkout -b my-feature-branch
git checkout master
git reset --hard HEAD〜1
git checkout my-feature-branch

解释:


  1. 首先我们确定我们在 master 分支。

  2. 现在我们创建一个新的功能分支,带来最新的提交。我们回到 master 分支。

  3. 我们重置 master 分支到最后一个之前的提交。

  4. 我们回到功能分支继续使用它。


Locally, I forgot to create a feature branch from the master branch, and then made a commit of my changes into the master branch.

How can i correct the mistake, so that the commit is removed from the master branch, and is made into a new feature branch?

Thanks.

解决方案

git checkout master
git checkout -b my-feature-branch
git checkout master
git reset --hard HEAD~1
git checkout my-feature-branch

Explanation:

  1. First we make sure we are on the master branch.
  2. Now we create a new feature branch, bringing along the latest commit.
  3. We move back to the master branch.
  4. We reset the master branch to the commit before the last one.
  5. We go back to the feature branch to continue working on it.

这篇关于如何补救意外地提交到主分支而不是我的功能分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆