在事实之后创建git分支? [英] creating git branch after the fact?

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

问题描述

我怀疑我的问题的答案非常简单,但我是一个git新手,我的头脑在阅读所有类似的SoF问题的答案时感到困惑,这些问题似乎并不是我的问题。



这里是我的问题:

我在github上有一个单独分支('master')的仓库,一直在我当地的回购中工作。在某个时候,我停止了将提交重新提交给github,因为我担心他们会破坏事情。所以现在我在我的本地仓库中有很多提交,我想要推回到github。

然而,与其推倒主人,我宁愿创建github上的一个新分支('development'),并将我所有的本地提交返回到该分支(我将在经过更好的测试后才会重新合并到master)。



有什么简单的方法可以做到这一点?

解决方案

关于master:



git checkout -b newbranch 或者如下所示,只需执行 git branch newbranch 即可创建新的分支没有切换到它。



这将创建一个分支,位于您当前在master处的提交。完成后:

git checkout master



通过:



git reset --hard< commit_hash>



其中< commit_hash> 应该被您想要master回滚的提交ID替换。



现在你可以切换到你的新分支并推送到远程。

  git checkout newbranch 
git push来源新分支


I suspect the answer to my problem is fairly simple, but I'm a git newbie and my head is getting confused at reading answers to all the similar SoF questions that don't seem to be quite my problem.

Here's my problem:

I have a repo at 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. So now I have lots of commits in my local repo that I want to push back up to github.

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?

解决方案

on master:

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

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

git checkout master

followed by:

git reset --hard <commit_hash>

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分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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