允许更改的文件不被git pull覆盖

允许更改的文件不被git pull覆盖,git,drupal,githooks,Git,Drupal,Githooks,我有这样的开发设置: /themes/themename/css/style.css # path to drupal theme css file /styleguide/source/css/style.css # path to generated css-file in styleguide styleguide为所有不同的页面类型提供了示例标记,这就是设计实现的地方。drupal主题css文件在git中跟踪,并在master中根据stylebuide中生成的css进行更新。然而

我有这样的开发设置:

/themes/themename/css/style.css   # path to drupal theme css file
/styleguide/source/css/style.css  # path to generated css-file in styleguide
styleguide为所有不同的页面类型提供了示例标记,这就是设计实现的地方。drupal主题css文件在git中跟踪,并在master中根据stylebuide中生成的css进行更新。然而,在我实现设计的同时,我需要不断地检查样式开发是否也正确地显示在drupal站点中。因此,我已设置软链接,以便:

/themes/themename/css/style.css -> /styleguide/source/css/style.css
这很好,我可以用drupal视图重新加载web浏览器,然后加载新生成的css文件

目前,我使用以下方法隐藏style.css已更改(对于git):

但是,每当我在现有分支上执行git拉取或git签出时,git都会抱怨说:

错误:您对以下文件的本地更改将被签出覆盖:
主题/uib_w3/css/style.css
请在切换分支之前提交或隐藏更改。
流产

有什么建议我可以避免收到这个消息吗?也许使用一些钩子在git pull上重置文件,然后重新建立链接post pull?或者还有其他更好的方法吗?

您可以“滥用”a,以便在签出时生成正确的
/themesame/css/style.css

  • 首先,不再使用版本
    style.css
    :将其重命名为“模板”。
    git mv style.css style.css.tpl

    /themes/themename/css/style.css
    添加到
    .gitignore

  • 第二,添加一个与
    *.css.tpl
    文件关联的污迹脚本:


(来自“”的图像,来自“”)

style_smudge
脚本可以进行版本控制,可以简单到:

#/bin/sh
cat
简言之:它对签出时的
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
”的环境变量(任意值),则您处于“开发”环境中,需要一个符号链接。

如果未设置相同的变量“
dev
”,则保留原始的
style.css
文件。

@VonC出于好奇,为什么这会被视为滥用该功能?@Clive,因为内容过滤器驱动程序应该修改过滤文件的内容。在这里,我们不考虑内容本身,而是在做各种不同的操作。
git config filter.checkcss.smudge 'style_smudge'
#/bin/sh
cat
#/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