I’ve been trying to write more detailed commit messages—breaking down what’s happening in big change sets, explaining problems I encountered and how I solved them, pointing out potential weaknesses in the code or future improvements—but it’s not easy to remember all the particulars while staring at the commit message editor.
Fortunately, Tmux can help.
I’ve written before about how to set up project workspaces in Tmux. My preferred workspace makes the first window a shell prompt at the project’s root directory. I use this shell primarily for Git operations: branching, reviewing changes, and committing. Thanks to the
tmux command, I can use this window for reviewing changes while writing the commit message. Here’s the command—I call it
tmux send "git diff --cached" C-m \; split-window -h \; send "git commit; exit" C-m
It’s simple but useful, automating something I could do manually, but making it more fun (which is important).
Here’s how it works:
1. First, it sends the keystrokes of the Git command to list the changes about to be committed.
2. Then, it creates a vertical split and a new pane within the window. In the new window, Tmux sends the keystrokes for the commands to commit and close the shell session.
git-review, I have a Tmux pane on the left with all of my changes and a pane on the right with my commit editor. Now it’s easy to switch back and forth between the two panes, seeing the changes in one and detailing the why in the other—the perfect recipe for better commit messages.