Reputation: 2043
Accidentally I forgot to open a new branch and committed my changes to the master, but haven't pushed them to the remote repo. Now I have the message : "Your branch is ahead of 'origin/master' by 1 commit."
What I would like to do is to make my master same as the master at the remote repo - by reverting to the previous state or by other means - and then open up a branch from there to be pushed to the remote. I don't mind re-making the changes I have made in my previous accidental commit.
When I :
cemgun@db05:~/mini$ git reset --hard
HEAD is now at 2e2adc9 SHBDN-8584 changes
cemgun@db05:~/mini$ git reset --hard
HEAD is now at 2e2adc9 SHBDN-8584 changes
I'm still at my accidental commit.
When I :
cemgun@db05:~/mini$ git checkout -f
Your branch is ahead of 'origin/master' by 1 commit.
cemgun@db05:~/mini$ git checkout -f
Your branch is ahead of 'origin/master' by 1 commit.
I'm still at my accidental commit.
Any suggestions ? Thx for your time.
Upvotes: 0
Views: 83
Reputation: 121
Try:
$ git reset --soft HEAD^
$ git checkout -b new_branch
This will undo the last commit, leaving the changes in the working repo, and then create new_branch containing those changes. You can then create a new commit in the new branch.
Upvotes: 2