I like the fine-grained commits that the git index allow, i.e. the staging of individual files or even hunks through git add before the final commit. Unfortunately, sometimes after spending some time staging a particular commit, muscle-memory kicks in so that I git commit -a -m "msg". Then I either have to live with it, or jump through some reset or --amend hoops.
Is there a way for me to (ideally, globally) configure Git so that if I issue a git commit -a, it gets intercepted? Maybe a script asking me to confirm if I really want to commit all? I’ve thought about delegating the commit operation to a wrapper script (e.g., “gitcommit”), but do not think that will work very well as it does not stop me from doing a git commit -a -m "msg", which is the problem in the first place.
Try pre-commit hooks:
something like this (not tested)
.git/hooks/pre-commit
You can find out the number of files to be committed using
git diff-index --cached HEAD | wc -l. But I think I would leave this to yourself.