Ricing git commit message
Published:
Problem
- The problem is we don’t have any convention about writing a good commit message. How a message should be? How your coworker can quickly grasp information from Git log of a project as much as possible? Do you remember how much time did you wasted because Git commit messages aren’t clear?
Message cateogry
- 📦 NEW: IMPERATIVE_MESSAGE
- Use when you add something entirely new.
- e.g., 📦 NEW: [EKO-2020] Implement websocket feature.
- e.g., 📦 NEW: [EKO-2020] Implement websocket feature.
- Use when you add something entirely new.
- 👌 IMPROVE: IMPERATIVE_MESSAGE
- Use when you improve/enhance piece of code like refactoring etc.
- e.g., 👌 IMPROVE: [EKO-2021] Refactor elasticsearch code.
- e.g., 👌 IMPROVE: [EKO-2021] Refactor elasticsearch code.
- Use when you improve/enhance piece of code like refactoring etc.
- 🐛 FIX: IMPERATIVE_MESSAGE
- Use when you fix a bug. Need I say more?
- e.g., 🐛 FIX: [EKO-2022] Notification not working.
- e.g., 🐛 FIX: [EKO-2022] Notification not working.
- Use when you fix a bug. Need I say more?
- 📖 DOC: IMPERATIVE_MESSAGE
- Use when you add documentation, like README.md or even inline docs.
- e.g., 📖 DOC: Add library documentation.
- e.g., 📖 DOC: Add library documentation.
- Use when you add documentation, like README.md or even inline docs.
- 🚀 RELEASE: IMPERATIVE_MESSAGE
- Use when you release a new version.
- e.g., 🚀 RELEASE: Version 2.0.0
- e.g., 🚀 RELEASE: Version 2.0.0
- Use when you release a new version.
Handy action
- Git alias is handy tool that save many efforts when performing git action, which is like (stored in .gitconfig file):
[alias] a = add --all ai = add -i
Pretty good but there is fix aliases. How can you use dynamic Git alias by having parameters? Or using external Linux command? Fortunately, Git alias template come to rescue:
my_alias = "!f() { 〈your complex command〉 }; f"
Let’s apply this technique to build our git alias for faster and easier way to write commit message:
# $@ to mean all command line parameters passed. # Git Commit, Add all and Push — in one step. # Git lets you use non-git commands and full sh shell syntax in your aliases if you prefix them with ! cap = "!f() { git add .; git commit -m \"$@\"; git push; }; f" # NEW. new = "!f() { git cap \"📦 NEW: $@\"; }; f" # IMPROVE. imp = "!f() { git cap \"👌 IMPROVE: $@\"; }; f" # FIX. fix = "!f() { git cap \"🐛 FIX: $@\"; }; f" # RELEASE. rlz = "!f() { git cap \"🚀 RELEASE: $@\"; }; f" # DOC. doc = "!f() { git cap \"📖 DOC: $@\"; }; f"
Paste into .gitconfig file under [alias] section and enjoy your result. Good luck.
Intellij Plugin
https://plugins.jetbrains.com/plugin/12383-gitmoji-plus-commit-button
Reference:
- https://riptutorial.com/git/example/2416/advanced-aliases
- https://www.atlassian.com/blog/git/advanced-git-aliases
- https://opensource.com/article/19/2/emoji-log-git-commit-messages
Thank for reading.