{"thread":{"id":"35913","subject":"Using \"git reset\" in a pre-commit hook can create an empty commit","startedAt":"2014-02-19T13:05:09Z","lastAt":"2014-02-19T13:05:09Z","messageCount":1,"participants":["Gunnar Strand"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"235054","messageId":"CAEsF1Lt8P8rSmhovbrWSyLE2HQLTjRA3sS-TK_pW6yzp_M+D3g@mail.gmail.com","threadId":"35913","inReplyTo":null,"subject":"Using \"git reset\" in a pre-commit hook can create an empty commit","fromName":"Gunnar Strand","fromEmail":"gurra.strand@gmail.com","sentAt":"2014-02-19T13:05:09Z","receivedAt":"2014-02-19T13:05:09Z","isPatch":false,"sender":{"key":"gurra.strand@gmail.com","avatar":null},"body":"Hi,\n\ngit version 1.8.4.2\nLinux 3.0.74-0.6.8-xen\n\n\"git commit\" does not properly reevaluate the state after the\npre-commit hook has been executed, and lists files which have been\nreset as part of the commit, and will create an empty commit, despite\nthat no \"--allow-empty\" was given.\n\nSteps to reproduce:\n\n1. Create a tracked file called \"ignoreme\"\n\n2. Add the following line to \".git/hooks/pre-commit\":\n\ngit reset HEAD ignoreme\n\n3. Make a change to the ignoreme file\n\n4. Run \"git commit -a\"\n\nResult:\n\nThe commit template will still list the file:\n\n# Changes to be committed:\n#   (use \"git reset HEAD <file>...\" to unstage)\n#\n# modified:   ignoreme\n#\n\n\nAdding a commit message will create an empty commit:\n\nign2$ git --no-pager diff HEAD^ HEAD\nign2$\n\nExpected behavior:\n\n- Git should refuse to continue if the pre-commit hook resets all changes\n- The commit message should not list files removed from the index\n\n\nBest Regards\nGunnar Strand\n"}]}