Lolo
Lolo

Reputation: 4159

Replacing the working directory with an earlier git commit

Here is the context:

How can I quickly update my working directory with earlier git commits until I find the first commit that introduced the bug? How do I then get back to my latest local commit?

I used hard git resets to do this recently and would have lost my last set of git commits if I hadn't found this answer so there must be another, safer way to achieve the same result.

Upvotes: 2

Views: 198

Answers (2)

Lolo
Lolo

Reputation: 4159

I just figured out the answer to my own question.

It's actually quite simple:

  1. Do git checkout of earlier versions until identifying the last version that does not exhibit the bug and the first one that does

  2. Then do a git switch to the master version to go back to the latest committed version

The checkouts are not intended to make further changes to the code but are quick and useful for updating the working directory without messing with the git directory, which is all what's needed to quickly pin-point the appearance of a new bug in the git tree.

Upvotes: 1

VonC
VonC

Reputation: 1324505

I am running into a bug in my latest version of the code and want to go back in time until the bug no longer shows up.

That is called git bisect, and is not implemented in Egit.

You should consider using git in command-line, in order to launch a bisect session.

Upvotes: 1

Related Questions