tags:

views:

53

answers:

2

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>
A: 

You could write a little shell script. One script would run git log --pretty=oneline | awk '{print $1;}'. The second script (call it step or something) would use head, tail, wc -l. Then read the last line of the file with tail, find out how many lines are in the file, and remove the last line from the file. Ugly, sure, but it'd do the job. :) (If you wanted to be a little less ugly, it could use truncate(1) to just chop off the last line of the file, rather than always making new temporary files.)

sarnold
A: 

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.

bstpierre
If the speed is a problem, you could store the output of `git rev-list <branch>`, and just find the line with your current HEAD on it and check out the line before.
Jefromi