I'm working on a list of what it means to "commit responsibly." What would you change/add to this?
Committing responsibly
- Using meaningful variables
- Not committing bugs or broken builds
- Not leaving in dead code or print statements
- Formatting code to style specifications
- Using descriptive commit messages
- Only committing code related to the change described in the message (one change per commit)
- Providing documentation where necessary
- Providing tests where necessary
Top comments (5)
A lot of these (the ones about the quality) I don't think are important in each commit, just so long as they're in place by the time you want to merge it into trunk/master.
For me, committing responsibly means you do
git status
to see what things have changed, you predict what you're going to see in the first file, you dogit diff firstfile
to make sure the change you see in that file is the change you expected to see. If you see something you need to change, you make the change and start again. If not, yougit add firstfile
to add it, and then you start over atgit status
, until you have the staging area built up to be the commit you want. This will make sure you know what you're committing (eg I've seen people accidentally commit random files, once it was even our private keys). This review will also help you write a good commit message.Also, commit messages should be in present tense. It keeps them shorter and easier to understand.
Another great practice is to include the ticket number within commit message.
Especially in legacy projects, sometimes is difficult to know why a change was made.
This depends on the dev culture of a place, but I do like committing daily. If someone gets hit by a bus or wins the lottery, it's far easier for someone else to pick up where you left of if you have your stuff on origin.
I'd rather see someone committing jibberish often than waiting 2 weeks to push up a perfect commit with the entire feature in one go.
I think your working title for the rant is hilarious XD And you're right, I noticed this with PRs. I tend to go look at the diffs first, to get an idea of what's going on, and more often than not find random small changes.
Haha this made me laugh I recognize the frustration all too well.