views:

182

answers:

3

I did a bit of development against the wrong branch in my local repository. I did a git branch without next doing a git checkout. The commands look something like this:

#On branch development
git branch release-v0.2.0b
# changes and several commits
git push origin release-v0.2.0b

And that's when I realized I was working on the wrong branch. My github repo is in the proper state, but my local repo isn't. I've merged the changes from development into release-v0.2.0b, but I'd like to reset development back to the way it is in my github repo. What's the best way to go about this?

A: 

Use git reset --hard

Eric Hogue
git reset --hard will not change the state of the local development branch, it will only undo edits to files and staged changes.
Jamey Hicks
+2  A: 

Go back to the local release branch you want the changes in, Pull there from github.

git checkout local-branch-that-refers-public-v0.2.0b
git pull origin release-v0.2.0b

Then, reset the branch pointer of the local branch that you committed to the earlier commit you want to go back to.

git checkout release-v0.2.0b
git reset HEAD^
Lakshman Prasad
+2  A: 

Just to make sure I understand the state of things: you created the release branch but did not check it out, so your commits are on the development branch in your local repository. You said you merged the changes into the release-v0.2.0b branch.

If that is the case, and there are no other commits on the development branch you need to preserve, just delete the local copy of the development branch and check it out again from origin.

First, verify what branches you have and which one you are on:

git branch -av

Then switch away from the development branch so you can delete it:

git checkout origin/development
git branch -D development

That actually leaves you on no branch, but you'll get back on a branch when you check it out again from the origin:

git checkout origin/development -b development

I suggest checking out origin/development to avoid unnecessary churning of files in your snapshot.

Jamey Hicks