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, the original template file was already loaded, so git init
does not overwrite. I read the same here, this appears to be the correct git behaviour:
From http://www.cs.potsdam.edu/cgi-bin/man/man2html?1+git-init:
Running git init in an existing repository is safe. It will not overwrite things that are already there. The primary reason for rerunning git init is to pick up newly added templates.
So what is a good way to force reloading new git template hooks? I have many hooks in many git repos, on several computers and used by a variety of users. 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. Is there a way of doing this?
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:
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
wechdir()
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
ingit-init.txt
mentions nothing about this behavior.
Change it to be relative to$CWD
, which is much more intuitive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With