git - How to fix commit to wrong branch -


i have question of how fix mistake did when committing , pushing code our repo @ bitbucket. situation had finished working on previous feature branch(branch1) , pulled master branch. proceeded create new branch(branch2) new feature.

what ended happening created branch2, did not check out updates ended being committed branch1.

how can transfer these changes branch1 branch2 ?

awesome paint picture included:

awesome paint graphics

if haven't pushed branch2 yet, 1 way go it:

git checkout branch1               # make sure on wrongly-modified branch1 git branch -d branch2              # remove current branch2 git branch branch2                 # create new branch2 @ current spot git fetch                          # make sure we're up-to-date on origin's pointers git reset --hard origin/branch1    # reset branch1 origin thinks should git checkout branch2               # switch branch2 # continue working on branch2 

i know it's lot type, should conceptually easy follow. find sometimes, if find smaller set of commands accomplish something, following logical easy understand approach better, when i'm working don't consider myself expert in yet...


Comments