How to undo git flow feature finish?

17,033

These steps should do the trick:

Get the sha's needed:

git log

<sha1> is the commit right before the merge
<sha2> is the last commit on develop before you started working on the feature

git checkout develop
git checkout -b feature/<feature-name>
git reset <sha1> --hard
git checkout develop
git reset <sha2> --hard

Push your feature branch.

Share:
17,033
hakunin
Author by

hakunin

Mirah pioneer, GAE lover, Entrepreneur wannabe

Updated on July 21, 2022

Comments

  • hakunin
    hakunin almost 2 years

    I am learning git-flow and I just did git flow feature finish <feature-name>, which merged my feature branch to develop and removed it.

    Instead of this, I want to push the feature branch to github, so I can merge it after a peer review.

    So the question is, how do I 'undo' this command. Or in other words , how can I move my last two commits from develop to my feature branch?

  • hakunin
    hakunin over 11 years
    I had to read this few times before I realized why reset on the feature branch (third line). Looks obvious in hidsight :) Thanks! (btw the <sha's> get lost in the markup)
  • Maikel D
    Maikel D almost 11 years
    This just saved my ass. Thanks Peter.
  • Rahul Roy
    Rahul Roy almost 10 years
    You saved my career. Thanks @Peter ;)
  • clemlatz
    clemlatz over 7 years
    If git flow feature finish was your last action, you can just do git reset --hard HEAD^ in both branches instead of using commit's shas, as the commits would be the lasts in boths cases.
  • clemlatz
    clemlatz over 7 years
    And if like me, you're trying to undo a hotfix finish, you also need to reset the last commit in the master branch.
  • Ultimo_m
    Ultimo_m almost 7 years
    you saved my weekend @Peter