清理git master分支并将一些提交移动到新分支? [英] Cleanup git master branch and move some commit to new branch?

查看:303
本文介绍了清理git master分支并将一些提交移动到新分支?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Github上有一个repo的克隆,我在其中为上游创建了一个新功能。问题是,我在我的主分支中做了这些,其中还包含其他我从其他克隆中抽取的东西。这完全打破了我创建合理的拉取请求的能力。



所以我想要做到以下几点:


  1. 恢复我的主分支与上游主分支完全相同。 创建一个新分支。

  2. 我的老提交给新的分支。

  3. 在分支上创建一个pull请求。

而且,未来,我会在分支机构完成所有工作,并在离开我的主分支时自行创建请求,并合并任何来自上游的请求。



我的问题是:


  1. 这是一个合理的方法吗?
  2. 1和3?


解决方案


$ b

  $ git branch old_master 

发送到远程备份(只是incase)

  $ git checkout old_master 
$ git push origin old_master

在开始修改内容之前重置本地主服务器到提交服务

  $ git checkout master 
$ git reset --hard 037hadh527bn

合并来自上游主人

  $ git拉上游主人

现在在远程repo上删除master



在github上,如果不先进入admin部分,并将临时分支临时设置为除master之外的其他分支,因为他们会尝试并保护您免受吹捧。

  $ git push origin:master 

重新创建它

  $ git push origin master 

在github上现在应该将默认分支设置回主设备

I have a clone of a repo on Github in which I created a new feature for upstream. The problem is, I did that in my master branch which also contains other stuff I pulled in from other clones. That totally broke my ability to create a reasonable pull request.

So I want to do the following:

  1. Restore my master branch to be exactly the same as upstream master.
  2. Create a new branch.
  3. Move some of my old commits to the new branch.
  4. Create a pull request off the branch.

And, in the future, I will do all my work in branches and create pull requests off them while leaving my master branch alone and just merging down whatever comes in from upstream.

My questions are:

  1. Is this a reasonable approach?
  2. How would I actually do steps 1 and 3?

解决方案

Make a new branch to hold stuff

$ git branch old_master

Send to remote for backup (just incase)

$ git checkout old_master
$ git push origin old_master

Reset local master to the commit before you started modifying stuff

$ git checkout master
$ git reset --hard 037hadh527bn

Merge in changes from upstream master

$ git pull upstream master

Now DELETE master on remote repo

On github this won't work without first going into the admin section for the fork and setting the default branch to something other than master temporarily as they try and protect you from blowing stuff away.

$ git push origin :master

And recreate it

$ git push origin master

On github you should now set the default branch back to master

这篇关于清理git master分支并将一些提交移动到新分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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