如何用git init用更新的版本替换本地git钩子?
我和这里的用户有完全一样的问题:
I have exactly the same question as this user here:
我的全局git钩子中有一个新的模板文件.但是,原始模板文件已经加载,因此git init
不会覆盖.我在这里读到的一样,这似乎是正确的git行为:
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:
来自 http://www.cs. potsdam.edu/cgi-bin/man/man2html?1+git-init :
在现有存储库中运行git init是安全的.它不会 覆盖已经存在的东西.主要原因 重新运行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.
那么强制重新加载新的git模板挂钩的好方法是什么?我在几台计算机上的许多git仓库中都有很多钩子,并且被各种用户使用.最实用的方法是让用户运行特定的命令,而不是先让用户删除该挂钩,然后再运行git init命令.有没有办法做到这一点?
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?
最实用的方法是让用户运行特定的命令,而不是先让用户删除该挂钩,然后再运行git init命令
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
在这种情况下,一种可能的方法是向这些用户分发执行该操作的脚本(您可以在每个存储库中对该脚本进行版本控制).
他们不会直接执行git init
,而是会调用该脚本,该脚本将:
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=
但是请注意--temaplate选项正在使用的路径.
赋予git init --template=<path> <repo>
的相对pathname
应该相对于调用目录"git init
"而言,
但它是相对于存储库(已
已通过Git 2.22.1(2019年第二季度)进行了纠正.
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).
请参见提交e1df7fe (2019年5月10日) ://github.com/pclouds"rel =" nofollow noreferrer>NguyễnTháiNgọcDuy(pclouds
).
(由 Junio C Hamano-gitster
-在
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:相对于
$CWD
的--template
路径在
git-init
期间,我们chdir()
到目标目录,但是--template
是 未调整.
因此它是相对于目标目录而不是当前目录的.
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.
如果有记录的话是可以的,但是git-init.txt
中的--template
对此行为一无所知.
相对于$CWD
进行更改,这更加直观.
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.