title: Can a Git hook automatically add files to the commit?
body: <p>I'd like to add an automatically generated file to the same commit using a pre- or post-commit hook in Git, dependent on the files that were modified in that commit.  How would I go about this?</p>
  
  <p>I've tried this as a pre-commit hook, but no luck:</p>
  
  <pre><code>#!/bin/sh
  files=`git diff --cached --name-status`
  re="&lt;files of importance&gt;"
  if [[ $files =~ $re ]]
  then
    echo "Creating files"
    exec bundle exec create_my_files
    exec git add my_files
    exec git commit --amend -C HEAD
  fi
  </code></pre>
  
  <p>This successfully adds them to the repository, but does not add them to the commit.  I've also tried using the last two exec lines in a post-commit hook along with the pre-commit inspection, but no good either.</p>