# Using "git reset" in a pre-commit hook can create an empty commit

1 messages from 2014-02-19 to 2014-02-19. Participants: Gunnar Strand.
Thread: https://gitlist.dev/t/35913

## Gunnar Strand, 2014-02-19 13:05

Subject: Using "git reset" in a pre-commit hook can create an empty commit
Message-ID: <CAEsF1Lt8P8rSmhovbrWSyLE2HQLTjRA3sS-TK_pW6yzp_M+D3g@mail.gmail.com>
URL: https://gitlist.dev/e/CAEsF1Lt8P8rSmhovbrWSyLE2HQLTjRA3sS-TK_pW6yzp_M%2BD3g%40mail.gmail.com

```
Hi,

git version 1.8.4.2
Linux 3.0.74-0.6.8-xen

"git commit" does not properly reevaluate the state after the
pre-commit hook has been executed, and lists files which have been
reset as part of the commit, and will create an empty commit, despite
that no "--allow-empty" was given.

Steps to reproduce:

1. Create a tracked file called "ignoreme"

2. Add the following line to ".git/hooks/pre-commit":

git reset HEAD ignoreme

3. Make a change to the ignoreme file

4. Run "git commit -a"

Result:

The commit template will still list the file:

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
# modified:   ignoreme
#


Adding a commit message will create an empty commit:

ign2$ git --no-pager diff HEAD^ HEAD
ign2$

Expected behavior:

- Git should refuse to continue if the pre-commit hook resets all changes
- The commit message should not list files removed from the index


Best Regards
Gunnar Strand

```
