user11301070
user11301070

Reputation:

How to roll back to a certain commit?

I have a list of commits. Need to roll back to some fit & upd (97f962f143b136d0d6dcbdfc02afc8253c767d7f). Need to do this so that all files that have been created in subsequent commits are deleted. enter image description here

git checkout 97f962f143b136d0d6dcbdfc02afc8253c767d7f

enter image description here

upd

enter image description here

Upvotes: 1

Views: 816

Answers (1)

Andrew Core
Andrew Core

Reputation: 78

Is your goal to delete all the commits after "some fit & upd," or just get a working tree in that state? I'm assuming you tried

git rest --hard 97f962f

If that failed, I would download the entire package from github at the specific commit you want and replace your working tree with those files. Probably not recommended or safe but I've done it a number of times (consider backing up your local repo).

Go to the repo on github.com. Click the "X commits" (leftmost button), navigate to the commit you want, click the name of the commit, click "Browse Files", "Clone or Download", and then download zip. You'll get a zip with the files as they were in that commit. If your HEAD is pointing where you want it, then replacing the files in your tree with the ones you downloaded should work.

There's probably something wrong with your repo if you're resorting to hacky solutions like this, but if it works it works.

You could consider trying git revert if reset isn't working. It isn't supposed to be used like this but you can create a new branch and revert all the commits between the most recent and the one you want (use the --no-commit option). You should end up with a working dir that matches the desired commit. Not a great way to do this but if reset isn't working at all then maybe it's worth a shot.

Upvotes: 4

Related Questions