作为存储库的一部分.gitattributes涂抹和清洁过滤器 [英] .gitattributes smudge and clean filters as a part of the repository

查看:117
本文介绍了作为存储库的一部分.gitattributes涂抹和清洁过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的git存储库中有许多模板文件,它们以不同的速率更改。这些被用来生成HTML页面。如果有人报告问题,我希望他们能够告诉我哪个版本的模板文件存在问题。目前,我在更改文件时手动输入日期。或者,我试着去。我大部分时间都忘记了。至少在理论上,我应该能够使用git smudge和clean filters来修复文件并自动插入上次更新的日期。这是非常棒的。除了我在一台机器上开发,当我准备好时,我推/拉到另一台机器上。

如何将污迹和清洁过滤器显示在另一台机器上?我不想在路径中添加奇怪的脚本;这仅仅是这个存储库所需要的,所以我想使它完全独立。网上的所有内容都说:将这个过滤器定义添加到〜/ .gitconfig中,然后将这些脚本添加到您的路径中,然后设置存储库.gitattributes文件。我想要它,所以如果我去一台新电脑并克隆存储库,所有的干净和污迹都会自动配置。



有没有人这样做?

解决方案

git clone ,您可以设置模板目录,它将声明这些配置。

即该模板文件夹将具有最少的 .gitconfig 与这些污迹/ clean指令:

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

只需设置(导出) GIT_TEMPLATE_DIR 引用该模板文件夹的环境变量。



通过使用以 $ {GIT_TEMPLATE_DIR} ,你不需要广告d将这些脚本添加到 $ PATH 中。这个脚本路径可能因机器而异:每个脚本路径可以有自己的 $ {GIT_TEMPLATE_DIR} 路径。



最后, .gitattributes 是您的回购协议的一部分,因此无需做任何事情。



你可以去一台新电脑并克隆存储库,所有的干净和污迹都会自动配置。

(前提是新电脑预装了它的模板目录)


I have a number of template files in my git repository which change at different rates. These are then used to generate HTML pages. If someone reports a problem, I want them to be able to tell me which version of the template file has the problem. Currently, I manually enter the date into the file when I change it. Or, well, I try to. I forget most of the time.

At least in theory, I should be able to use git smudge and clean filters to fix the files and insert the date of last update automatically. This would be great.

Except that I develop on one machine, and when I'm ready, I push/pull to a different machine.

How do I get the smudge and clean filters to show up on the other machine? I don't want to have to add odd scripts to the path; this is only needed for this one repository, so I want to make it entirely self-contained. Everything online says "add this filter definition to your ~/.gitconfig, then add these scripts to your path, then set up the repository .gitattributes file". I want it so that if I go to a new computer and clone the repository, all of the clean and smudge is configured automatically.

Has anyone done this?

解决方案

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)

这篇关于作为存储库的一部分.gitattributes涂抹和清洁过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆