d
Amit DhamuSoftware Engineer
 

Step Through Commits On A Branch In Git

1 minute read 00000 views

Open a terminal window and do the following.

for commit in $(git rev-list <branch> --reverse)
do
    git checkout $commit
    read
done

Each time you press Enter, it will step through to the next commit on the branch.

Have a second terminal window open to check stuff in the repository.

Credit

Alternatively, you can use git-bisect to pinpoint the commit where a problem might have started occurring. Assuming master is currently "bad":

git checkout master
❯ git pull
❯ git bisect start
❯ git bisect bad
❯ git bisect good a8dbfe1 # last hash where the code was "good"

At this point, git will checkout revisions based on what you've told it and you can check each one. If it's good, simply put git bisect good and it will move to the next one and so on until you've found the culprit.