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 --allow-empty makes a commit with no changes

Git
~/tips/tip-git-commit-allow-empty

git commit --allow-empty -m "Trigger CI"

Records a commit that changes no files, for example to restart a CI run.

Git normally refuses a commit that has the same tree as its parent, which is a sensible default. Now and then an empty commit is exactly what you want, and there is a flag for it.

git commit --allow-empty -m "Trigger CI"

This records a commit with no file changes. The classic reason is to start a pipeline again when something outside the repository was fixed, such as an expired secret or a runner that was offline. Another is a marker in the history, for example the start of a new phase, with a message that says what happened.

The manual explains the default: a commit with the same tree as its only parent is usually a mistake, so git stops you. It adds that the flag is mainly meant for scripts that talk to other version control systems, so it is not a thing to use all day.

Caveats: the empty commit stays in the history for everyone, so write a message that makes sense in a year. If the branch is going to be squashed, it disappears at merge time. And if all you need is a rerun, many CI services have a button for that which leaves no trace in git.

Related and rarely needed: --allow-empty-message allows a commit with no message at all.

Further reading: git commit, –allow-empty (Git documentation)

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