git/list[1] front-page[2] threads[3] people[4] search[5] about
 

COMMIT_EDITMSG not updated after pre-commit hook

From
HSHinrik Örn Sigurðsson <hinrik.sig@gmail.com>
Date
May 3, 2009, 23:20 UTC
Message-ID
<6e4c323b0905031620m48769dbdp52684d6b470ebea3@mail.gmail.com>

I have a pre-commit hook which extracts documentation from file $foo if it has pending changes to be committed. The hook creates/updates the documentation file and calls "git add" on it.

When I do "git commit", the COMMIT_EDITMSG delivered to my editor notes that this documentation file has been created/updated, but not that its changes have been added to the index. However, if I go ahead with the commit, I can see that the doc file changes were indeed committed.

Here is a simplified test case:

$ cat .git/hooks/pre-commit #!/usr/bin/env perl use strict; use warnings;

my $old = qx"git rev-parse HEAD:foo 2>/dev/null"; my $new = qx"git rev-parse :foo 2>/dev/null";

if (($? >> 8) != 0 || $old ne $new) {
    system "cat source > dest";
    system "git add dest";
}

$ ls source

$ echo 123 >> source

$ git status # On branch master # Changed but not updated: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: source # no changes added to commit (use "git add" and/or "git commit -a")

$ git commit -a
Test commit
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   source
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#       dest
[master 535ed7f] Test commit
 2 files changed, 3 insertions(+), 0 deletions(-)
 create mode 100644 dest

$ git status # On branch master nothing to commit (working directory clean)

Next: Ævar Arnfjörð Bjarmason
Message 1 of 4 in “COMMIT_EDITMSG not updated after pre-commit hook”
  1. Hinrik Örn SigurðssonMay 3, 2009
  2. commit: update the index after running the pre-commit hookÆvar Arnfjörð Bjarmason, Aug 18, 2010
  3. Junio C HamanoAug 18, 2010
  4. Jonathan NiederAug 18, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.