5 ms·
Depends on whether you consider `git commit --allow-empty` a weird quirk ... I guess it would be reasonable to do so ;).
by mjochim 4y ago
Depends on whether you consider `git commit --allow-empty` a weird quirk ... I guess it would be reasonable to do so ;).
- mywittyname 4y agoWhat's the purpose of this? I can think of ways to use/abuse it, but there has to be a specific reason that it was added as a feature to git.
- maxfurman 4y agoI see `--allow-empty` in git tutorials all the time, to demonstrate the concept of a commit. I'm not sure when you'd reach for it in a real repo though
- eyelidlessness 4y agoThe most obvious reason not involving automated systems is to create a repo’s initial ref. This can be useful on teams who are super strict about review process and git history. Once you account for automated systems, many other reasons can arise. Not just the “trigger CI” case mentioned in another comment, triggering builds or processes based on remote content the code accesses, or generating something either random or seeded by the commit hash/timestamp/message/etc. It can even be a Homer Simpson-style drinking bird button press, so finished software doesn’t get mistaken for abandoned. Probably whole worlds of things I haven’t imagined because I don’t use git hooks or submodules.
- dixie_land 4y agogit commit --allow-empty -m "trigger CI job"
- ezekg 4y agoI use it to trigger CI/CD. And for example, when upgrading Heroku's dyno stack, when is applied on next deployment. heroku stack:set heroku-22 git commit -m 'upgrade to heroku-22 stack' --allow-empty git push heroku master
- gh02t 4y agoMaybe so you can make an empty initial commit and push it to a remote like Github as a placeholder? Or a lazy way to trigger a CI job when you're gonna squash and cleanup later. I guess conceptually you could use it to represent "I started from nothing."
- bryanlarsen 4y agoI've found it useful when interactively rebasing a series of commits to make a nice PR. The code moved to a different commit, but I didn't want to lose the message.
- ok_dad 4y agoFor those of us who start projects often, but never finish them: git commit --allow-empty -m "Initial commit."
- mdaniel 4y agoI use it extensively for entire PR based development; that way all the code that ended up in the repo has had multiple eyes (and an opportunity to comment) upon it git commit --allow-empty -m "initial" git push -u origin HEAD git checkout -b first-pr # type-y type-y
- kadoban 4y agoThe most common reason I see it is to create the initial commit of a repo. This is useful both so you have something to push to a remote, PR against, and because several git commands (most notably rebase variants) need weird switches (eg --root) if you _don't_ have an empty initial commit to refer to instead.