我最近搞砸了我的git repo,想知道是否有任何补救措施.
我的设置是这样的:
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)
我的工作流程是这样的:
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
这样我在我的主人分支中总是有一个原始的中央状态.
现在我所做的就是开始在Master分支上工作.所以我对我的主人进行了更改,并且不再从中分支以获得Central的副本.每当我需要制作并推送一些修复到Central时,我必须将Central克隆到另一个目录并从那里开始工作.
我的问题:有没有办法将我的主人"恢复"为中央的相同副本,同时将我在主人身上所做的所有更改移到另一个分支(比如功能)?
我知道这很令人困惑,我很感激任何帮助.我会澄清是否有任何不清楚的地方.
Pat Notz和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 #
现在我有两个很好的分支:master和old_master.master是我的Central的副本,用于修复生产,old_master持有我之前做过的所有工作!
谢谢!
# 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 # Reset my local master back to match origin/master $ git reset --hard origin/master
现在,您可以检出old_master
并使用它,就像你做你的feature
分支