# Git Commit Allow Empty: a commit with no changes

Published: 2026-11-30

Rights: original
Source: https://kairos-2z6s.onrender.com/res/git-commit-allow-empty-full-en
`git commit` with nothing staged refuses; in this run the exit status was 1. `git commit --allow-empty -m MESSAGE` records a commit with no file changes.

Each command below is the exact command that was run and each output block is copied from the recorded log. Test ids, log hashes and exit statuses are in the evidence table.

(Test: 3 tests were run, TE-92-A, TE-92-B and TE-92-C. The expected non-zero exit is TE-92-C (exit status 1). Every row has a recorded log, and the exit statuses and log hashes are in the evidence table.)

### TE-92-A: a plain commit with nothing staged fails, --allow-empty succeeds

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git commit -qm nothing >/dev/null 2>&1; echo plain=$?; git commit -q --allow-empty -m marker; echo empty=$?; echo commits=$(git log --oneline | wc -l); git show --stat --format=%s HEAD | head -1
```

Recorded output:

```
plain=1
empty=0
commits=2
marker
```

Exit status: 0. The output matches the expected text written before the run. This is the status of head, the last command in the pipe.

### TE-92-B: an empty commit changes no file between its parent and itself

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git commit -q --allow-empty -m marker; git diff --name-only HEAD~1 HEAD | wc -l; git log -1 --format=%s
```

Recorded output:

```
0
marker
```

Exit status: 0. This status and the output match what was written before the run. This is the status of git log, the last command.

### TE-92-C: expected non-zero exit: git commit with nothing staged prints that there is nothing to commit and exits with status 1

Setup for this run, inside a throwaway directory (`mktemp -d`):

```bash
git init -q .
git symbolic-ref HEAD refs/heads/main
git config user.email test@example.invalid
git config user.name tester
git config commit.gpgsign false
printf 'a\n' > f.txt; git add f.txt; git commit -qm one
```

Command:

```bash
git commit -m nothing
```

Recorded output:

```
On branch main
nothing to commit, working tree clean
```

Exit status: 1. This status and the output match what was written before the run.

TE-92-B: the empty commit was made, git diff --name-only between its parent and itself printed no file name, so the count is 0, and the newest subject is marker. TE-92-C: git commit -m nothing in a clean repository exited with status 1. Standard output has the two lines On branch main and nothing to commit, working tree clean.

## Limits

TE-92-A shows the exit status and the commit count, TE-92-B shows that the empty commit changes no file, and TE-92-C shows the refusal text. Using empty commits to trigger other tools was not tested.

## Source

- https://git-scm.com/docs/git-commit

## Evidence table

| Test | What it checks | Exit | Verdict | Log sha256 (first 12) |
|---|---|---|---|---|
| `TE-92-A` | a plain commit with nothing staged fails, --allow-empty succeeds | 0 | PASS | `2d11513d490e` |
| `TE-92-B` | an empty commit changes no file between its parent and itself | 0 | PASS | `07f74dee457f` |
| `TE-92-C` | expected non-zero exit: git commit with nothing staged prints that there is nothing to commit and exits with status 1 | 1 | PASS | `84184ee30d90` |

Recorded on: bash 5.1.16(1)-release; git version 2.34.1; Python 3.10.12. Locale C.UTF-8, TZ=UTC.
Every row has a recorded log holding the setup commands, the command, stdout, stderr and exit status. The first 12 characters of the log's sha256 are in the table.

## Related guides
- [Git Log -S: find the commit that added or removed a string](https://kairos-2z6s.onrender.com/res/git-log-s-full-en)
- [Git Config Get: read one setting](https://kairos-2z6s.onrender.com/res/git-config-get-full-en)
- [Git Blame: who last changed each line](https://kairos-2z6s.onrender.com/res/git-blame-full-en)
- [Git Commit Amend: replace the last commit](https://kairos-2z6s.onrender.com/res/git-commit-amend-full-en)
- [git clean: delete untracked files, with a dry run first](https://kairos-2z6s.onrender.com/res/git-clean-full-en)
