quick-notes

📓 Git Notes

💻 Useful Commands

✅ Commits

The Point of Good Commits

Information Anatomy of a Good Commit

A diff will show you what has changed in the codebase, and the commit message is what tells you why something has changed the way it has.

The Structure of a Good Commit

  <type>(<scope>): <subject>
  <body>
  <footer>

I think the most important parts are the subject and body. I’m a big fan of type too. I haven’t used footer, because the convention in teams I’ve work on is to include Jira ticket numbers in the commit subject, and I also haven’t used scope, which hasn’t had an obvious use in my particular projects so far.

Example commit without a footer.

git commit -m "chore(server): JIRA-123 - Update routing dependencies in Node server

The previous version of the routing library in the Node server is not compatible with the latest OurCoolAPI changes."

Example commit with a footer.

git commit -m "chore(server): Update routing dependencies in Node server

The previous version of the routing library in the Node server is not compatible with the latest OurCoolAPI changes.

Resolves: JIRA-123
Related: PR #87, PR #86"

Tools for Making Good Commits

Granular staging with interactive mode!

To help make atomic commits, you can stage chunks of code – you don’t have to stage an entire file at once!3 in VS Code there’s a way to visually select chunks to stage, as shown in the image below. You can also right click on the section of code you want to stage and an open will appear in the context menu for staging/un-staging the selected range.

Image showing how to use interactive staging mode through VS Code interface

From the command line, you can do this with the git add --patch and git add --interactive for interactive modes.4

Other Resources For Good Commits

🛠️ Tools

💡 Tips

📙 Resources

📚 References