2

Here is the context:

  • I am using egit within Eclipse

  • I made a number of commits that I have not pushed to the remote repository

  • I suddenly notice a bug with my app that wasn't there before

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.

Community
  • 1
  • 1
Lolo
  • 3,411
  • 4
  • 34
  • 45
  • It sounds like you want to [create a new branch from a previous commit](http://stackoverflow.com/questions/2816715/branch-from-a-previous-commit-using-git). When you're finished experimenting,, you can switch back to your original branch and merge in the changes if you'd like. – Ben Dec 03 '14 at 06:20
  • 2
    That would work but I realize I missed one important clarification in my question: 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. If I have to create a branch for every older version I want to check, that would quickly become cumbersome. Isn't there another way to achieve the same result without creating any branch? – Lolo Dec 03 '14 at 06:25
  • 1
    Take a look at [git bisect](http://git-scm.com/docs/git-bisect), that should help you finding the commit which introduced the bug. – Sascha Wolf Dec 03 '14 at 06:27

2 Answers2

1

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.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks: that looks like a useful little tool to have when searching through a very large number of commit versions. – Lolo Dec 03 '14 at 14:08
1

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.

Lolo
  • 3,411
  • 4
  • 34
  • 45