Tag: pre commit hook

Git钩子能否自动添加文件到提交?

我想使用Git中的提交前或提交后钩子,将自动生成的文件添加到相同的提交中,具体取决于在提交中修改的文件。 我将如何去做这件事? 我已经试过这个作为预先提交的钩子,但没有运气: #!/bin/sh files=`git diff –cached –name-status` re="<files of importance>" 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 这成功地将它们添加到存储库,但不会将它们添加到提交。 我也试过在post-commit hook和pre-commit检查中使用最后两个exec行,但是也不行。