Skip to content

Instantly share code, notes, and snippets.

@carloshhr
Last active March 15, 2018 13:30
Show Gist options
  • Save carloshhr/c3f812244db52c51c6956c44882b7215 to your computer and use it in GitHub Desktop.
Save carloshhr/c3f812244db52c51c6956c44882b7215 to your computer and use it in GitHub Desktop.
Git command if you push a commit to a branch and you want to come back to previous commits
If you have a branch like this
Master
7243798 M
60789fc M
4c629bb M
And you push 6bbw138 commit by mistake to Master your result will be:
Master
6bbw138
7243798 M
60789fc M
4c629bb M
If you want to come back to 7243798 or previous
1) on local repo go to your master branch:
git checkout master
2) Then we need the commit id to do a a reset of master branch in our case 7243798
git reset --hard 7243798
3) We need to push this change to our branch, in our case is master branch
git push origin master -f
I used bitbucket repo, this will be the output
Total 0 (delta 0), reused 0 (delta 0)
To bitbucket.org:square1/www.myrepo.test.git
+ 6bbw138...7243798 master -> master (forced update)
And that's it you will have your branch on the previous commit.
Master
7243798 M
60789fc M
4c629bb M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment