【发布时间】:2011-03-18 02:11:37
【问题描述】:
我想使用 Git 中的 pre-commit 或 post-commit 挂钩将自动生成的文件添加到同一个提交中,具体取决于在该提交中修改的文件。我该怎么办?
我已尝试将此作为预提交挂钩,但没有运气:
#!/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
这成功地将它们添加到存储库中,但不会将它们添加到提交中。我还尝试在提交后挂钩中使用最后两个 exec 行以及提交前检查,但也没有好处。
【问题讨论】:
-
您需要从此代码中删除
execs(请参阅man sh)。在exec之后执行任何shell 命令都是不可能的,因为exec破坏了当前进程,即用于解释命令的shell。
标签: git pre-commit-hook githooks pre-commit