我有这样的开发设置:
/themes/themename/css/style.css # path to drupal theme css file
/styleguide/source/css/style.css # path to generated css-file in styleguide
样式指南具有针对所有不同页面类型的示例标记,这就是完成设计实现的地方。 drupal 主题 css 文件在 git 中进行跟踪,并根据 stylebuide 中生成的 css 在 master 中进行更新。然而,在实现设计时,我经常需要检查样式开发是否也在 drupal 站点中正确显示。因此,我设置了一个软链接(soft link),以便:
/themes/themename/css/style.css -> /styleguide/source/css/style.css
这很好用,我可以使用 drupal View 重新加载 Web 浏览器,然后加载新生成的 css 文件。
目前我 stash 了 style.css 已更改(对于 git)的事实,使用:
git update-index --assume-unchanged /themes/themename/css/style.css
但是,每当我在现有分支上执行 git pull 或 git checkout 时,git 都会提示:
error: Your local changes to the following files would be overwritten by checkout:
themes/uib_w3/css/style.css
Please, commit your changes or stash them before you can switch branches.
Aborting
有什么建议可以让我避免收到此消息吗?也许使用一些钩子(Hook)来重置 git pull 上的文件,并在 pull 后重新建立链接?或者还有其他可能效果更好的方法吗?
最佳答案
您可以“滥用”content filter driver为了在 checkout 时生成正确的 /themes/themename/css/style.css
:
首先,不要再对
style.css
进行版本控制:将其重命名为"template"。
git mv style.css style.css.tpl
。
将/themes/themename/css/style.css
添加到.gitignore
中。第二,添加与
.gitattributes
declaration 中的*.css.tpl
文件关联的涂抹脚本。 :*.css.tpl filter=checkcss
(图片来自“Customizing Git - Git Attributes ”,来自“Pro Git book ”)
git config filter.checkcss.smudge 'style_smudge'
style_smudge
脚本可以进行版本控制,并且可以简单如下:
#/bin/sh
cat
简而言之:它在 checkout 时对 style.css.tpl
没有任何作用。
但是,您可以使用(实际上是滥用)该污迹脚本来执行其他操作:
#/bin/sh
if [ -z ${dev+x} ]; then
ln -fs /styleguide/source/css/style.css /themes/themename/css/style.css
else
cp -f /themes/themename/css/style.css.tpl /themes/themename/css/style
fi
cat
如果定义了名为“dev
”的环境变量(为任何值),则您处于“开发”环境,并且需要符号链接(symbolic link)。
如果未设置同一变量“dev
”,则保留原始 style.css
文件。
关于git - 允许更改的文件不被 git pull 覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34743353/