I’m coaching @dylangrafmyre on what happens when you’re ready to commit code, so here’s a quick checklist. Let me know if there’s anything to add.
Commit Checklist
Get all the tests passing first (if possible).
Open up a scratchpad to start jotting down the commit message.
Go through each diff (in RubyMine):
Remove any debug print statements.
Ensure that the right level of commenting is used. No comments that are better done with code. Use comments for something like some test code that should work but doesn’t and that might get fixed by some gem upgrades.
Remove any commented code.
Clean up formatting for changed lines.
Consider whether the set of changes should be one commit or multiple commits.
Run the tests again if you’ve changed any files.
The goals for each commit should be to:
Tell a small, self-contained story.
Make it easy for your code reviewer.
Be useful for running a git bisect to track down any regressions.
So wait, this is for each and every commit? Or would you use incremental commits, and this is for “roll-up” type commits? I’m a much bigger fan of very prolific committing… It’s a dirtier history later, but much easier in the long term to go back to “working” states…
For my checklist, that’s every commit. It only takes a very short time to run through my list, with the exception of running the test suite. I think Martin’s list is great as well, and that’s something I should strive for, as the JetBrains tools have great static analysis. However, I think I never get around to running the static analysis as the dynamic analysis gets most issues.
Another tip is to not immediately push commits, so that you can revise the history a bit if needed before committing.
I think there is some middle ground. Like @litch I commit regularly, sometimes 10 times a day. I would die if I had to run through all that every time. What I do is develop in a branch with LOTS frequent commits. But when its time to merge back to master, your list looks to be comprehensive. Personally, I despise commits that break tests, so I would rethink saying “if possible” on item #1.
@justin this is exactly what I do. I seem to always get the number of commits to include in the rebase incorrect, however, which is very annoying. What’s the trick here? For example if I make 3 commits after a commit tagged 1.0.0, and I want to squash them into a single commit that comes immediately after 1.0.0, what is the exact thing you’d write? git rebase -i HEAD~3?
If you found the solution to some problem, include the link to that stack overflow discussion or blog post in your commit message, so it’ll be easier to track down if you need it again.
First git rebase -i <SOME SHA> my feature branch into a single commit. I generally have to look at the history to see how far back to rebase -i. There’s probably a script for this.
Then I git fetch && git rebase origin/master and that puts my one uber-commit on top of master.
Once I deem everything ready, I do a git push -f, making sure nobody was working at the same time off of my feature branch.
I bet there’s a better, more automated way to do this.