在多次提交后创建git分支

在多次提交后创建git分支

本文介绍了在多次提交后创建git分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在GitHub上有一个存储库,其中有一个我一直在本地存储库中使用的分支master.在某个时候,我停止将提交推送回GitHub上,因为我担心它们会破坏事情.现在,我在本地存储库中有很多提交,我想将其提交回GitHub.

I have a repo on GitHub with a single branch master that I've been working on in my local repo. At some point I stopped pushing commits back up to master on GitHub because I was worried that they'd break things. Now I have lots of commits in my local repo that I want to push back up to GitHub.

但是,我宁愿在GitHub(development)上创建一个新分支,而不是将其推送回master,然后将所有本地提交推送回该分支(只有在它们合并后,我才将其合并回master).进行了更好的测试).

However, rather than pushing back up to master I would prefer to create a new branch on GitHub (development) and push all my local commits back up to that branch (which I will merge back into master only after they've been better tested).

执行此操作的简单方法是什么?

What is the simple way to do this?

推荐答案

在主机上:

git checkout -b newbranch或如下建议,只需执行git branch newbranch即可创建新分支,而无需切换到该分支.

git checkout -b newbranch or as suggested below, simply do a git branch newbranch to create the new branch without switching to it.

这将创建一个分支,该分支是您当前在master上提交的.完成后:

This will create a branch that is at your current commit at master. Once done:

git checkout master

其次:

git reset --hard <commit_hash>

<commit_hash>的位置应替换为您希望主服务器回滚的提交ID.

Where <commit_hash> should be replaced by the commit ID you want master rolled back to.

现在,您可以切换到新分支并将其推出到遥控器.

Now you can switch to your new branch and push it out to the remote.

git checkout newbranch
git push origin newbranch

这篇关于在多次提交后创建git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 11:50