0

I have the following situation. A commit where my project works. The next commit where something horrible that I can not explain happens. So

badcommit (HEAD->master) How horrible!
goodcommit Here it works

so I did git checkout goodcommit and I got my project working again! (pheew!).

 goodcommit(HEAD) Here it works

So now I want to start from here and forget that horrible experience. I read you can revert a commit. So How can I put master in goodcommit and continue from there?

(I read very complicated answers but I remember it was very simple: a one line command that took the last commit and reverted to the previous one, not -like I read- a series of complicated commands)

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • 3
    Possible duplicate of [How to revert a Git repository to a previous commit](https://stackoverflow.com/questions/4114095/how-to-revert-a-git-repository-to-a-previous-commit) – OliverRadini Aug 13 '18 at 09:35
  • You've checked out the good commit. Now create a branch at that point and keep going, or reset the old branch to the good commit. – evolutionxbox Aug 13 '18 at 09:36
  • @evolutionxbox Yeah I could do that but would lose the master branch. So revert is needed – KansaiRobot Aug 13 '18 at 09:39
  • Why would you lose the master branch? Have you made many commits since the bad one? – evolutionxbox Aug 13 '18 at 09:41
  • See https://stackoverflow.com/q/51814990/1256452 as well. This particular question and its answers is/are intended for: "we've been working for a week, made dozens of commits, and now we all need to go back to one-week-ago". For your particular simple case you just want one `git revert` or `git reset`. – torek Aug 13 '18 at 15:16

1 Answers1

2

You can use following commands,

git log

It will provide you list of your previous commits, copy that long string from the commit, then use

$ git reset --hard <COMMIT -ID>

Example: git reset --hard 6504ab87416af0571ae628511207813f20bb2d2c

That's it.

Neeraj
  • 652
  • 10
  • 18