1

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

  • 2
    Possible duplicate of [git checkout - How do I revert a git repository to a previous commit](https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit) – isstiaung Jun 18 '19 at 16:56
  • it's don't work –  Jun 18 '19 at 17:14
  • 2
    Possible duplicate of [How do I revert a Git repository to a previous commit?](https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit) – phd Jun 18 '19 at 17:29
  • `git checkout master && git reset --hard 97f962f143b136d0d6dcbdfc02afc8253c767d7f` – phd Jun 18 '19 at 17:30
  • @phd Already on “master” Your branch has been updated in accordance with "origin / master". HEAD is now at 97f962f some fit & upd –  Jun 18 '19 at 17:41
  • @phd But the files have not changed, the applications remain ... –  Jun 18 '19 at 17:41
  • @phd see screen –  Jun 18 '19 at 17:43
  • Better show `git status`. Also try `git clean -dfx` to remove non-tracked files. – phd Jun 18 '19 at 18:30

1 Answers1

4

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.

  • 1
    `git revert`? here? This doesn't achieve what OP wants, but it dangerously *sounds* like it. If he did that, he would end up in an even more convoluted situation... at least please explain the link you see between the situation and revert, how to apply it, how to get back... something. Help me not downvoting your answer :-) – Romain Valeri Jun 18 '19 at 20:05
  • You're right, this isn't the intended use of git revert. But you can use it to rollback a bunch of commits in a row correct? Reset is the correct tool here, but if that's failing then I personally would try a massive revert on a new branch and see what happens. – Andrew Core Jun 18 '19 at 20:31
  • This is why I didn't downvote : yes it is possible to revert every commit past the one OP deemed "good". But also yes : it would likely be more than heavy to operate, compared to alternatives. – Romain Valeri Jun 18 '19 at 20:33
  • Gotcha, thanks for making me clarify that as simply mentioning it casually was a bad idea. Do you know if reset and revert have different strategies? That is, if reset isn't working then would revert have a chance? – Andrew Core Jun 18 '19 at 20:38
  • 1
    There are many articles on the subject, and it would be difficult to go in details here of course... I found [this one](https://webdevstudios.com/2017/07/20/fixing-things-git-reset-vs-revert/) pretty useful. 35 points for a good start. Yay! – Romain Valeri Jun 18 '19 at 20:48
  • Wow very informative read, thanks! And thanks again for nudging me to make this answer better, SO relies on friendly users like yourself :) – Andrew Core Jun 18 '19 at 22:43