问题描述
我有一个预提交的挂钩,
I have a pre-commit hook that:
- 检查是否需要更新我的版本文件
- 修改所述文件
- 对此文件执行git添加
这使我可以将更新的版本文件添加到同一提交中.我唯一的问题是,在挂钩运行后,工作树和HEAD将使用新版本文件进行更新,但索引不是.我需要手动暂存索引的版本文件以反映更改.
This allows me to add the updated version file to the same commit.The only problem I have is, after the hook runs the working tree and HEAD are updated with the new version file but the index isn't. I need to manually stage the version file for the index to reflect the changes.
我将git更新为2.3.4,但这并不能解决任何问题.
I updated git to 2.3.4 but that doesn't solve anything.
我在这里想念什么吗?
版本文件的当前设置:
- 每个模块都包含一个版本文件
- 它们存储在这里:
/module/<模块名称>/version.txt
- 它们包含一个手动输入的版本号(例如1.5.2)和父提交哈希
推荐答案
我添加了一个提交后钩子,该钩子将自动对版本文件进行 git add
(如果有的话).如果有人对此问题有更好/更轻松/更清洁的解决方案,请告诉我.
I have added a post-commit hook that will automatically do a git add
of the version file (if there is one). If anyone has a better/easier/cleaner fix for this issue let me know.
对于那些感兴趣的人,这是提交后的内容:
For those interested this is the post-commit:
for fn in `git diff-tree -r --name-only --no-commit-id develop`; do
if [[ $fn == *"version.txt" ]];then #prevent infinite loops that will eventually fill up the entire harddrive
echo "post-commit hook found a version file at $fn"
git add $fn
fi
done
这篇关于在预提交挂钩中执行git add后,为什么索引未更新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!