Josh Morrison
Josh Morrison

Reputation: 7636

git ,how to go back?

I did these operation:

$ bundle exec rspec spec/
$ git add .
$ git commit -m "Finished layout and routes"
$ git checkout master
$ git merge filling-in-layout
$ git push 
$ git push heroku

But then I found the program messed up. I want to go back to last commit. Both local and github and heroku. How can I do this?

Upvotes: 2

Views: 1048

Answers (2)

cdhowie
cdhowie

Reputation: 169133

Assuming that both master and filling-in-layout are the branches you touched:

# Reset master to its previous commit
git checkout master
git reset --hard master@{1}

# Reset filling-in-layout to its previous commit
git checkout filling-in-layout
git reset --hard filling-in-layout@{1}

# Push to GitHub, forcing the loss of history
git push --force

# Same, for the heroku remote
git push --force heroku

Upvotes: 0

Kit Ho
Kit Ho

Reputation: 26998

In all of your branch, type

git reset --hard HEAD^

this will reset and discard all the changes to the last commit.

if you don't want to discard your changes in wrong commit, you can use

git reset --mixed HEAD^

Upvotes: 3

Related Questions