Why is the index not updated after doing a git add in a pre-commit hook?

六眼飞鱼酱① 提交于 2019-12-06 06:00:17
VonC

You would be better off with a content filter driver, more specifically a clean filter.

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")

That filter (associated to the version file through a .gitattributes declaration) would run automatically on git diff and git commit, and would:

  • detect if the version needs to change
  • update the version file if needed

That way, a regular commit would end up committing an updated version file. Automatically.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!