-1

Lets say i have 20 commits on a project in github. After 20 commits i feel like my program is running slow. I there fore want to go back and test when the programs slows down. I simply cant figure out what command i need to use to sync my local drive with a specific commit id from github. Please help, i know this is probably very simple. How

Ive tried git checkout, but this creates a new branch or something

git checkout <SHA HASH>
Ali Beadle
  • 4,486
  • 3
  • 30
  • 55
TobiasKnudsen
  • 527
  • 2
  • 9
  • 29

1 Answers1

0

Actually you can use git checkout like you tried. As long as you don't use the -b option, this does not create a new branch, but leaves you with a detached HEAD (i. e. HEAD points to a specific commit, not to a branch), so exactly what you want.

If you do not want to test one commit after another to find the point where it slows down, you instead might want to use git bisect which supports exactly your usecase of efficiently finding one specific commit where something changes. This could be the commit where a bug was introduced, or the commit where something became slow or whatever. It supports this by a binary search algorithm, meaning you give it a commit where the project was slow and a commit where the project was fast, then Git checks out the middle between them. You then tell Git whether this commit is slow or fast and so on until Git tells you it has found the first commit where the project became slow, based on your input. You usually need waaaay less tries to find the commit in question than when testing one commit after another.

Your command would be something like git bisect start --term-old=fast --term-new=slow @ @~20 if you know it is slow at the current commit and was fast 20 commits ago. Then after testing the checked out code you will call git bisect slow or git bisect fast until you found the commit in question. If you can determine whether the code is slow or fast programmatically, you can even give git bisect a script that tells bisect with its return value whether the commit is slow, fast or indeterminate (e. g. build fails so slow or fast cannot be measured) and Git will autmatically find you the commit in question without anymore manual intervention.

Vampire
  • 35,631
  • 4
  • 76
  • 102