Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
91 views
in Technique[技术] by (71.8m points)

Git reset to previous commit

I have three commits I made which I attempted to clean up some code. Anyways I managed to completely destroy what I was working on. And I want to delete the past three commits and return to a specific commit SHA1.

How can I restore to that previous commit and delete the history of those 3 commits? (The history deleting part is not a big deal). These commits are pushed already, so I am a little lost.

Thanks!

question from:https://stackoverflow.com/questions/9764288/git-reset-to-previous-commit

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since your commits are pushed remotely you need to remove them. I'll assume your branch is master and it's pushed over origin.

You first need to remove master from origin:

git push origin :master (note the colon)

Then you need to get master to the status you want, I'll assume the commit hash is ABCDE:

git reset --hard ABCDE

Lastly, push master again:

git push origin master

That's it! Note that if someone already downloaded your changes from origin this will screw them pretty much leaving their local repos unstable.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...