创建git分支,并将原始状态还原为上游状态 [英] Create git branch, and revert original to upstream state

查看:240
本文介绍了创建git分支,并将原始状态还原为上游状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的设置是这样的:

$ b

我最近搞砸了我的git repo,并想知道是否有任何补救措施。
$ b

  github上的中央回购。 
github上的个人回购(这是中央分支)
+ Central设置为远程(上游/主控)
+主分支(原产地/主控)
+功能分支(来源/功能)

我的工作流程如下所示:

 需要在Central中修正某些内容:
1. checkout Master
2.进行更改
3.从上游/
3.提交,推送至上游/主账户

需要处理新功能:
1.结帐/创建功能分支
2.工作工作
3.从上游/主控制器拉出并合并
4.提交,推向上游/主控制器

通过这种方式,我的主分支中始终保持原始状态。

现在我所做的就是开始在Master分支上工作。因此,我对主人进行了更改,不能再从中分出来获取中央副本。每当我需要制作并向Central推送一些修复程序时,我必须将中心克隆到另一个目录并从那里开始工作。



我的问题:是否有办法还原我的主人是中央的一个完全相同的副本,同时将我对主人所做的所有更改转移到另一个分支(比如说Feature)?

我知道这是令人困惑,我会很感激任何帮助。我会澄清,如果有什么不清楚的。

解决方案

好的解决方案非常简单,由Pat Notz和Bombe暗示。

 #确保我们在master分支
$ git checkout master

#Make a新分支举行工作我已经完成了
$ git分支old_master
#将此分支保存在我的远程仓库中(用于备份)
$ git checkout old_master
$ git push origin old_master

#重新设置我的本地主控制器以匹配我刚开始前的提交
#处理我的新功能
$ git checkout master
$ git reset - 硬2aa93842342342
#让它与我的中央一样
$ git pull上游主

#现在删除我的远程仓库中的主人
$ git push origin :master
#并重新创建
$ git push origin master

#创建分支!
#* [新分支] master - > master


现在我有两个很好的分支:master和old_master。主人作为我的中央副本,修复生产,old_master持有我以前所做的所有工作!



谢谢!


I recently screwed up my git repo and would like to find out if there is any remedy to it.

My setup is this:

Central repo on github.
Personal repo on github (which is a fork of Central)
   +Central is setup as remote (upstream/master)
   +Master branch (origin/master)
   +Feature branch (origin/feature)

My workflow was like this:

Need to fix something in Central:
   1. checkout Master
   2. Make changes
   3. Pull from upstream/master and merge
   3. Commit, push to upstream/master

Need to work on a New Feature:
   1. Checkout/Create Feature branch
   2. Work work work
   3. Pull from upstream/master and merge
   4. Commit, push to upstream/master

This way I always had a pristine state of Central in my Master branch.

Now what I did was started working on Master branch instead. So I made changes to my master and can no longer branch from it to get a copy of Central. Whenever I need to make and push some fixes to Central, i have to clone the Central into another directory and work from there.

My question: Is there a way to "revert" my master to be an identical copy of the Central, while moving all the changes I have made on my Master into another branch (say Feature)?

I know it's confusing, and I would appreciate any help. I will clarify if anything is unclear.

解决方案

Well the solution was pretty simple, hinted by Pat Notz and Bombe.

#Make sure we're on the master branch
$ git checkout master

# Make a new branch to hold the work I've done
$ git branch old_master
# Save this branch on my remote repo (for backup)
$ git checkout old_master
$ git push origin old_master

# Reset my local master back to match the commit just before I started 
# working on my new feature
$ git checkout master
$ git reset --hard 2aa93842342342
# Get it to be the same as my Central
$ git pull upstream master

# Now DELETE my master on my remote repo
$ git push origin :master
# And recreate it
$ git push origin master

# Branch created!
#* [new branch]      master -> master

#

Now I have two nice branches: master and old_master. With master being a copy of my Central, for fixes to production, and old_master holding all the work that I did previously!

Thanks!

这篇关于创建git分支,并将原始状态还原为上游状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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