.gitattributes smudge and clean filters as a part of the repository

爷,独闯天下 提交于 2019-12-03 11:11:34

As mentioned in git clone, you can setup a template directory which will declare those configuration.
Ie that template folder would have a minimal .gitconfig with those smudge/clean directives:

filter.manage_date.smudge ${GIT_TEMPLATE_DIR}/smudge-script
filter.manage_date.clean ${GIT_TEMPLATE_DIR}/clean-script

Simply set (export) a GIT_TEMPLATE_DIR environment variable referencing that template folder.

By using an absolute path starting with ${GIT_TEMPLATE_DIR}, you won't need to add those scripts to a $PATH. And that script path can differ from machine to machine: each one can have its own ${GIT_TEMPLATE_DIR} path.

Finally, the .gitattributes is part of your repo, so nothing to do there.

With that setup, you can "go to a new computer and clone the repository, all of the clean and smudge is configured automatically."
(provided that new computer has its template-dir pre-populated)

Specify a template that does what you want when cloning, or supply a repo-setup script and type sh repo-setup after cloning, or put the necessary commands in a paragraph in the README and say V}!sh or however your editor pipes commands through the shell, or use git archive for distribution rather than git push, since that supports arbitrary keyword substitution. Turning a bare git clone into a code-injection vector seems like a bad price to pay to avoid trivial inconveniences like this.

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