Marc Strapetz <> writes:

> When using "git commit --amend --only --message <message> --", I'd
> expect to have just the commit message of my last commit changed,
> according to the man page:
> "--only Make a commit only from the paths specified on the command line,
> disregarding any contents that have been staged so far. [...] If this
> option is specified together with --amend, then no paths need to be
> specified, which can be used to amend the last commit without committing
> changes that have already been staged."
> However, all staged changes are committed as well. So looks like either
> the man page or Git is wrong here!?

I do not think the combination with --amend, --only and no paths
ever worked.  We rejected such a combination before 6a74642c5, which
merely made us to accept the combination but I do not think the
commit did anything to re-read the tree from the HEAD being amended
to the index.

Something like this, but I haven't thought about what other things
it may break.

 builtin/commit.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index f43eaaf..59ef5e1 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -184,6 +184,9 @@ static int list_paths(struct string_list *list, const char 
        int i;
        char *m;
+       if (!pattern)
+               return 0;
        for (i = 0; pattern[i]; i++)
        m = xcalloc(1, i);
@@ -345,7 +348,7 @@ static char *prepare_index(int argc, const char **argv, 
const char *prefix,
         * and create commit from the_index.
         * We still need to refresh the index here.
-       if (!pathspec || !*pathspec) {
+       if (!(only && amend) && (!pathspec || !*pathspec)) {
                fd = hold_locked_index(&index_lock, 1);
                if (active_cache_changed) {

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to