Restore your Github Pull Request to certain commit

Maybe you have pushed to your PR a commit that messes your code or your testing suite.

One thing you can do to restore your Pull Request is the next one:

For example, imagine my commit Remove unexpected keyword_end is messing my code and the last commit that were my code was good was Change schema after run migrations

$ git log
commit 3f5bade980f157e18641e665be6ab557d6e4dd6d  
Author: Victor Velazquez <[email protected]>  
Date:   Tue Apr 11 18:28:26 2017 -0500

    Remove unexpected keyword_end

commit 9ad0db1f8167c05716a72f8034012835f9acc6e6  
Author: Victor Velazquez <[email protected]>  
Date:   Tue Apr 11 18:08:53 2017 -0500

    Change schema after run migrations

commit 29913538aedb59ea659067b320b8745b7fd0193a  
Merge: 5909c5c 4a377a6  
Author: Victor Velazquez <[email protected]>  
Date:   Tue Apr 11 18:07:28 2017 -0500

    Merge branch 'master' into feature/test-feature

Now do a checkout to the sha key of your good commit,

$ git checkout 9ad0db1f8167c05716a72f8034012835f9acc6e6

Then create a temporary branch

$ git checkout -b fix

After that, you can push forced that branch pointing to your origin branch:

$ git push origin fix:feature/test-feature -f

And then you are good to go.

To maintain sanity in your local branch, don't forget to delete your temp branch and your local main branch you are using:

$ git checkout master
$ git branch -D fix
$ git branch -D feature/test-feature
$ git fetch origin

Then you are ready to jump back to your current branch:

$ git checkout feature/test-feature
$ git log
commit 9ad0db1f8167c05716a72f8034012835f9acc6e6  
Author: Victor Velazquez <[email protected]>  
Date:   Tue Apr 11 18:08:53 2017 -0500

    Change schema after run migrations

commit 29913538aedb59ea659067b320b8745b7fd0193a  
Merge: 5909c5c 4a377a6  
Author: Victor Velazquez <[email protected]>  
Date:   Tue Apr 11 18:07:28 2017 -0500

    Merge branch 'master' into feature/test-feature

And that's all folks!

Victor Velazquez

Coder, Musician, Startups, Passionate Dancer & Life Lover. Software Engineer at MagmaLabs, Co-founder of Web Dev Talks, Co-founder of Voltaire, Co-founder of Paqkit, Ex-co-founder of Zaznova.

Subscribe to The zazvick's blog

Get the latest posts delivered right to your inbox.

or subscribe via RSS with Feedly!