Jon not doe xx
Jon not doe xx

Reputation: 563

Test old commit in Git Repository

I currently have a Project(JavaScript) with a bug in it and I am sure that I fixed it sometime ago, now my Question is how to revert to an old commit and check that Version on my localhost.

But I do not want to loose any changes in my git repo I just want to check how the Project look at commit X, how do I manage that.

I am using gitkraken as a gui.

Upvotes: 3

Views: 3187

Answers (2)

Timothy Truckle
Timothy Truckle

Reputation: 15624

If you are unsure when the bug was introduced/fiex you can use the bisect approach of git: https://git-scm.com/docs/git-bisect

git bisect start
git bisect bad COMMIT_KNOWN_TO_FAIL
git bisect good COMMIT_KNOWN_TO_PASS

Then git will select a commit in the middle. You can do your check and depending on the result of your test you call:

 git bisect good

if the test passes and

 git bisect bad

if the test fails.

Then git selects another commit towards the former good if the test failed and towards the **bad* if the test passed.

Since you're looking for when the problem disappeard you might have to switch the meaning of "good" and "bad" when continuing...

when you identified the malicios commit call

git bisect reset

Upvotes: 0

kowsky
kowsky

Reputation: 14539

  • Be sure you have no uncommited changes; commit or stash them if necessary
  • Create a new branch at your current HEAD (using the Branch button)
  • Search the commit you want to take a look at
  • Right click the commit, choose Reset <branchname> to this commit > Hard - discard all changes. This will reset the branch you just created to this commit.
  • You travelled back in time. Test and check everything you need to. If you want to go back to the present, just check out your original branch.

EDIT: There's an even easier way!

  • Be sure you have no uncommited changes; commit or stash them if necessary
  • Search the commit you want to take a look at
  • Right click the commit, choose Create branch here. Enter a branch name. This will create a branch at this commit.
  • Check out the newly created branch by double-clicking.
  • You travelled back in time. Test and check everything you need to. If you want to go back to the present, just check out your original branch.

Upvotes: 3

Related Questions