How to replace local git hooks with updated versions with git init?

后端 未结 1 1399
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 18:28

I have exactly the same question as this user here:

git init template, replacing modified hooks

I have a new template file in my global git hooks. However, t

相关标签:
1条回答
  • 2021-01-11 18:54

    The most practical way is to have the users run a specific command, rather than telling them to remove the hook first and then run the git init command

    In that case, a possible way would be to distribute to those users a script which does just that (you could version that script in each of your repo).
    Instead of doing the git init directly, they would call that script which would:

    • remove the hooks
    • call the git init --template=

    But beware of the path you are using with the --temaplate option.
    A relative pathname given to "git init --template=<path> <repo>" ought to be relative to the directory "git init" gets invoked in, but it instead was made relative to the repository, which has been corrected with Git 2.22.1 (Q2 2019).

    See commit e1df7fe (10 May 2019) by Nguyễn Thái Ngọc Duy (pclouds).
    (Merged by Junio C Hamano -- gitster -- in commit 35d7715, 25 Jul 2019)

    init: make --template path relative to $CWD

    During git-init we chdir() to the target directory, but --template is not adjusted.
    So it's relative to the target directory instead of current directory.

    It would be ok if it's documented, but --template in git-init.txt mentions nothing about this behavior.
    Change it to be relative to $CWD, which is much more intuitive.

    0 讨论(0)
提交回复
热议问题