6

I'm using SourceTree and Git-Flow pattern. Now I have prepared a release for my beta-testers to test so I created a new release/v1.0.1 branch. But my mind slipped and I decided to finish (merge into develop and master and tag) the release even though I haven't even sent out the release to my testers. So I would like to have the release branch open up again if my testers finds any bugs I can fix these bugs in the release branch and then when all bugs are fixed I can finish the release.

So how can I easily with SourceTree preferably (or using git commands) revert back to the state when I had the release/v1.0.1 branch?

Attached screendump from SourceTree:

enter image description here

EDIT: Okay I did the git reset --hard HEAD~2 on develop (HEAD~2) because I had tested manually checking out. But now when I checkout master and do a git reflog it seems to me that I should do a reset on HEAD~6

Peters-MacBook-Pro:Remessage peterwarbo$ git reflog
f7663b1 HEAD@{0}: checkout: moving from develop to master
3d132da HEAD@{1}: reset: moving to HEAD~2
2f1c753 HEAD@{2}: checkout: moving from master to develop
f7663b1 HEAD@{3}: checkout: moving from develop to master
2f1c753 HEAD@{4}: merge release/v1.0.1: Merge made by the 'recursive' strategy.
4332fe4 HEAD@{5}: checkout: moving from master to develop
f7663b1 HEAD@{6}: merge release/v1.0.1: Merge made by the 'recursive' strategy.
fe323ef HEAD@{7}: checkout: moving from release/v1.0.1 to master
28a63ea HEAD@{8}: commit: Bumped version number to 1.0.1

But when I do that I get this "error":

Peters-MacBook-Pro:Project peterwarbo$ git reset --hard HEAD~6
fatal: ambiguous argument 'HEAD~6': unknown revision or path not in the working tree.

EDIT 2: New image to illustrate fuckup.

enter image description here

EDIT 3: Attached new image to illustrate the current state now after issuing the git commands in user1615903´s answer. Why does it say that develop is 2 behind? And why is there a merge from release/v1.0.1 to master even though I did a reset to master to the initial commit (fe323ef)?

enter image description here

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • So basically you just need to remove the last commit in master and in develop, and set 28a63ea as "release/v1.0.1" again? – 1615903 Apr 18 '13 at 11:12
  • I believe so? I also need to remove the merge that was done to `master` and `develop` – Peter Warbo Apr 18 '13 at 11:14
  • The tag should be removed as well. Basically I just want to go back in time to the state when I had created the `release/v1.0.1` branch and made that commit to bump the version number. – Peter Warbo Apr 18 '13 at 11:19
  • 3
    `HEAD~6` (6 commits back from HEAD) is not the same as `HEAD@{6}` (6 git operations ago) – Gareth Apr 18 '13 at 12:05

1 Answers1

14

This is quite easy. Things you will need to do are:

  • Reset develop branch to the commit it was before merge

  • Reset master branch to the commit it was before merge

  • Have the release branch point to the correct commit again

  • Remove the tag

  • Push the fixed commits to remote

So to do steps 1 and 2:

git checkout develop
git reset --hard 4332fe4

git checkout master
git reset --hard <SHA of the commit the master was before the merge>

Then to "recreate" the release branch:

git checkout -b "release/v1.0.1" 28a63ea

And finally to remove the tag:

git tag -d v1.0.1

More information about undoing a merge in this stackoverflow question

After that, if the changes were already pushed, you need to use the -f switch to override changes in remote:

git push -f

And to delete the tag from the remote:

git push --delete origin v1.0.1
Community
  • 1
  • 1
1615903
  • 32,635
  • 12
  • 70
  • 99
  • I tried what you recommended but I seem to be stuck now? See my updated question please. – Peter Warbo Apr 18 '13 at 11:46
  • So, you did reset with HEAD~2? That means you moved the branch tip two commits behind, and now you are trying to move it 6 more commits behind? Please include a new picture from SourceTree, it really helps to illustrate this. – 1615903 Apr 18 '13 at 11:51
  • So I foobared? Can I undo that? (I have my repository mirrored at Bitbucket fortunately) I'm uploading new picture now. – Peter Warbo Apr 18 '13 at 11:54
  • Edited my answer so that it refers to commit SHA's instead of HEAD-something. Don't worry, it's really difficult to PERMANENTLY delete things in git. – 1615903 Apr 18 '13 at 11:55
  • 1
    let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28438/discussion-between-user1615903-and-peter-warbo) – 1615903 Apr 18 '13 at 11:59