[This behavior was originally reported in https://stackoverflow.com/q/76022720/147356.] Prior to commit 03267e8656, the following sequence would result in an empty commit: git init testrepo date > testrepo/testfile git -C testrepo add testfile git -C testrepo commit -m test --allow-empty --only After commit 03267e8656, the same sequence creates a commit that contains "testfile". I believe the original behavior was correct, based on the documentation for the `--only` option: > If used together with --allow-empty paths are also not required, and > an empty commit will be created. A simple change that corrects this behavior would be to prevent git from refreshing the cache when --only is active: diff --git a/builtin/commit.c b/builtin/commit.c index 9d8e1ea91a..8c441548f8 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -995,7 +995,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct object_id oid; const char *parent = "HEAD"; - if (!the_index.cache_nr) { + if (!the_index.cache_nr && !only) { discard_index(&the_index); if (repo_read_index(the_repository) < 0) die(_("Cannot read index")); And while that passes all the tests, I'm not sure if its correct; the change in 03267e8656 was correcting a memory leak and I'm not sure I completely understand the details. -- Lars Kellogg-Stedman <lars@xxxxxxxxxx> | larsks @ {irc,twitter,github} http://blog.oddbit.com/ | N1LKS