Git-支持异国字符集

4
我正在abas-ERP的环境下工作,它使用一个名为abas-s3的奇怪字符集,由于历史原因。我们使用Git在ERP服务器上进行本地版本控制。
Git自然不支持abas-s3。在ERP服务器上有一个名为s3_conv的程序,它可以将abas-s3转换为外部世界(例如UTF-8和UTF-16)以及相反方向。
有没有办法使用该程序,将存储库用UTF-8表示,而将工作树用s3表示?
感谢您的帮助!提前致谢!
1个回答

2
如果问题出在文件内容上,你可以使用clean/smudge filters(请参见gitattributes)让 Git 在存储到仓库时转换为 UTF-8,在将内容检出到工作区时转换为 abas-s3。
你也可以在Pro Git书中找到解释。
总结:
  1. You need to define in the config file (per repository, per user, or system-wide) a filter consisting of two commands: clean that transforms from working area representation to repository representation, and smudge that works in reverse. Assuming that s3_conv works like iconv, it could look like this (this is a fragment of appropriate config file):

    [filter "s3conv"]
        clean  = s3_conv --from abas-s3 --to utf-8
        smudge = s3_conv --from utf-8 --to abas-s3
    
  2. Declare with gitattributes file (inside repository, or per-repository, or per-user, or system-wide) which files should be transformed using this operation. Assuming that you want to transform files with SQL, using *.sql extension, appropriate fragment of a file could look like this (note that there cannot be whitespace around = here):

    *.sql filter=s3conv
    
请注意,Git 无编码偏好,您不需要转换文件内容...除非您需要进行交互操作?
如果您需要让git diff正确显示更改(假设您没有能够显示abas-s3编码并且可以在core.pager中使用的分页器),您可能想要配置textconv过滤器而不是
  1. In config file:

    [diff "s3conv"]
         textconv = s3_conv --from abas-s3 --to utf-8
    

    This assumes that terminal and pager is configured to display utf-8

  2. In gitattributes file:

    *.sql diff=s3conv
    

感谢您的回答,很抱歉我回复晚了。我会在周一尝试这个方法,并告诉您结果! - Nils-o-mat
这正是我正在寻找的。非常感谢! - Nils-o-mat

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接