Awesome Git Commit Message
Last updated: Jul 13, 2019
Why care about commit message anyways? What’s the need?
We write commit message to get a glance of development activity. Hence writing Awesome commit message might mean people scouring through git logs would be able to undestand development activity better and faster.
Here are some tips to write awesome git commit messages.
- Use present tense: add awesome-package, not added …
- Use preceding subsystem when applicable: registry: add theme foobar
- 50 characters or less for the first line of your commit
- Use of emoji is free1
How to automate this process?
git commit hook to check/lint commit messages for issue IDs
git log --pretty=oneline --abbrev-commit \ | cut --delimiter=' ' --fields=1 --complement \ | grep '\[.*\]' --count
git staged | unstaged files
git adding your files and later changing them, git may again ask you to stage
your files! Why is that?
when you change a file which is already in the repository, you have to git add it again if you want it to be staged.
This allows you to commit only a subset of the changes you made since the last commit. For example, let’s say you have file a, file b and file c. You modify file a and file b but the changes are very different in nature and you don’t want all of them to be in one single commit. You issue
git add a git commit file_a -m "bugfix, in a" git add b git commit file_b -m "new feature, in b" # if you want to commit everything you can just type git commit -a
How to unstage a file?
git rm --cached <filePath> does not unstage a file, it actually stages the removal of the file(s) from the repo (assuming it was already committed before) but leaves the file in your working tree (leaving you with an untracked file). will unstage the file for future commits also. It’s unstaged untill it gets added again with git add
git reset -- <filePath> will unstages the file in the current commit.