Create git branch, and revert original to upstream state

前端 未结 3 1106
长发绾君心
长发绾君心 2020-12-23 10:12

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         


        
3条回答
  •  失恋的感觉
    2020-12-23 10:40

    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!

提交回复
热议问题