brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git commit -v shows your diff while you write the message

Git
~/tips/tip-git-commit-verbose

git commit -v

Shows the staged diff in your editor while you write the commit message.

Writing a commit message from memory is how you end up with “fix stuff”. I’d rather see what I’m committing while I type, and git can put it right there in the editor.

git commit -v

With -v (or --verbose) git adds the diff between HEAD and what you staged at the bottom of the commit message template. You scroll down, read what changed, and write the message above it. The diff isn’t part of the message: git leaves it out of the commit when you save and close the editor.

Give it twice and you also see the changes you didn’t stage yet in tracked files. That’s a nice way to catch the edit you meant to include and forgot to git add:

git commit -vv

I’d make it the default, because there’s no real reason to write a message blind:

git config --global commit.verbose true

commit.verbose also takes a number, so setting it to 2 gives you the -vv view every time.

One caveat: it only helps when git opens an editor. With git commit -m "..." there’s no template, so there’s nothing to look at. And on a big commit the file in your editor gets long, so jump to the top before you start typing, because the message goes above the diff, not below it.

Further reading: git-commit documentation, git-config documentation

Going deeper: Guide: advanced tmux, a config that grows with you, formats, layouts and more

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link