Creating an empty commit in Git
Dzhavat Ushev

Dzhavat Ushev @dzhavat

About: Front-end developer trying to make useful stuff.

Location:
Kolding, Denmark
Joined:
Jun 21, 2019

Creating an empty commit in Git

Publish Date: Mar 31 '24
4 4

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
Enter fullscreen mode Exit fullscreen mode

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

Comments 4 total

  • Makar
    MakarMar 31, 2024

    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

    • Dzhavat Ushev
      Dzhavat UshevApr 2, 2024

      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 :)

      • Makar
        MakarApr 2, 2024

        hmm, very interesting, I have never had such an issue -- that must be pretty annoying

        • Dzhavat Ushev
          Dzhavat UshevApr 3, 2024

          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 😬

Add comment