Does this sounds familiar - a Continuous integration (CI) pipeline is stuck and you need to push a new commit to restart it?
So now you’re looking for a place where you can make a dummy change like deleting/adding an empty line, adding/deleting a dot in a comment - any change, so you can make a new commit and push it upstream.
“There must be a way to create empty commits” you tell yourself but you’re too busy looking for a place to make that dummy change instead of searching for a solution to your problem.
Well, there is a better way!
Git allows you to create an empty commit by simply adding the --allow-empty
flag to the commig
command. Here 👇
git commit -m "chore: empty commit" --allow-empty
Your job is done. 🎉
Thanks for reading. See you in the next post 😎
Thanks to my colleague Morten Hansen for showing me this tip.
Photo by Kate Trysh on Unsplash
Top comments (4)
It used to be a pain point over a year ago for GitHub Actions, but now they have 2 buttons on the workflows allowing to re-run all test steps or just the failed ones -- sound better to me compared to cluttering the git history with empty commits
Yes, you're right. There's a way to rerun only particular jobs in a pipeline. But I'm not sure whether there's a way to restart a pipeline that is stuck, e.g. it hasn't even started due to some reason (we've had such cases). In this case pushing an arbitrary change forces the pipeline to restart. That's where the empty commit comes into the picture. Instead of making a dummy change just to commit something :)
hmm, very interesting, I have never had such an issue -- that must be pretty annoying
Yeah, it is. We have a kind of "master" workflow which runs first, whose purpose is to determine which other workflows should run. When the "master" workflow gets stuck, nothing else runs 😬