Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to step through a git repository?

Tags:

git

branch

I am trying to understand a project, it helps to look at its evolution by using gitk. What I do is checkout the first commit, understand code, run tests, go to next commit and repeat. My current workflow is to checkout the commit through its hash

git checkout 79cd6

But what I would like is another branch where I can perform my own changes, and allows me to merge commits from the master branch, but without the need to find the commit hash. Idealized workflow:

git checkout -b <newbranch> <first commit id of master>
git <command to move head of current branch to next commit of master>
like image 567
carrutherji Avatar asked Jul 21 '10 04:07

carrutherji


2 Answers

Save this as ~/bin/git-next or somewhere else in your path:

#!/bin/bash
git co $(git rev-list --children --all | awk "/^$(git rev-parse @\{0})/ { print \$2; }")

This will check out the first child of the current revision.

It will be very slow on a big repo but it will do the job.

You can modify this to handle your branching as needed.

like image 33
bstpierre Avatar answered Sep 28 '22 03:09

bstpierre


I know this is a bit of an old question, but I wanted to do the same thing and found an answer so I figured I'd share.

for commit in $(git rev-list master --reverse)
do
    git checkout $commit
    read
done

do this in one window. It will start with your initial commit, and advance once each time you hit enter. Then do your testing etc. in a different shell.
It'll work perfectly with a linear history, but I'm not quite sure how it will handle merges and such. I'm sure it'll be reasonable, but your mileage might vary a bit.

like image 104
FellowMD Avatar answered Sep 28 '22 04:09

FellowMD