Easy local code-review with git
When multiple developers contribute to a project, keeping on top of the constant flow changes can be a challenge. The following simple review workflow assumes a shared git-repository with a fairly linear commit-history, that is, not having too many merge-commits.
So, assuming a fairly linear history of commits from multiple developers, how do you easily keep track of what you have already read through and reviewed? Easy, use a local branch as a bookmark. This tiny script makes it trivial to add or update such a branch:
Save this as a new file called reviewed.sh
in your PATH
.
Usage is extremely simple:
Running one of these commands will mark the given treeish as reviewed, and when you look at your commit-history in a visual tool such as git gui
or gitx
, the reviewed
branch visually indicates how far you have gotten. Note how both commit-IDs, branch names, tags, and relative commit-IDs can be used as argument.
You can also utilize this review bookmark from the commandline. The following shows you all commits added to master since your last review:
git log reviewed..master --reverse
You can add a --patch
to that command to see the full diff for each change. Adding --format=oneline
just shows you the commit-IDs and first line of the commit-message.
Once you’ve read all the latest commits on master, simply do a
reviewed.sh master
and you’re done.
Why not use a tag?
I find it convenient to be able to do a push of all tags to the central repository with
git push --tags
and this would share such a private review-tag. As this is my private reminder of how far in the commit-history I have reviewed, sharing it is just confusing to other developers.
Notice: Any commits which are added only to the reviewed
branch are unreferenced when you mark a new treeish as reviewed. Just something to keep in mind.
How do you keep track of the flow of changes?
Hi, I'm Laust Rud Jacobsen, an experienced webapp developer specializing in Elixir, Ruby and PostgreSQL-based solutions. You can hire me to build awesome stuff for you. If you have any questions or comments, reach out at @laustrud or privately at work@valuestream.io.