这个git smudge / clean过滤器有什么问题? [英] What is wrong with this git smudge/clean filter?

查看:361
本文介绍了这个git smudge / clean过滤器有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的git存储库中应用这个过滤器,以便在结帐时从解决方案文件中删除一部分,并在提交过程中添加此部分。



这是我想删除或添加:

pre $ code $ GlobalSection(SubversionScc)= preSolution
Svn-Managed = True
经理= AnkhSVN - Subversion支持Visual Studio
EndGlobalSection

.git / info / attributes

lockquote
sln filter = SourceControlProvider

,我已经将这些命令添加到我的配置
$ b $ pre $ git config filter.SourceControlProvider.smudge sed -e'/ GlobalSection(SubversionScc)/,/ EndGlobalSection / d'%
$ git config filter.SourceControlProvider.cleansed -n -e'/ ^ Global $ / r ankhsvnsection'<%

好吧,它不起作用。我做了什么错误?

ankhsvnsection是一个与* .sln文件位于同一目录的文本文件


  1. 您有在这两个过滤器的末尾。
    这没有特别的意义,并将作为额外的参数传递给 sed ,这将可能会产生一个错误(除非你有一个名为的文件)。
    过滤器应该是streaming(从标准输入读取并写入标准输出)。他们的定义可以包含%f ,但是它不应该被当作一个文件来读写。 Git做这个部分,过滤器应该从标准输入读取并写入标准输出。

  2. 你的干净的过滤器试图从%f

    输入的数据已经在stdin上,不需要重定向。 清洁过滤器中的 sed 程序使用 r 命令访问另一个文件。

    过滤器似乎从在工作树,但我不知道这是否有保证。
  3. 清洁过滤器中的 sed 命令使用 -n 。它的唯一输出将是 ankhsvnsection 文件的内容(假设输入有一个全局行)。


  4. 某些版本的 sed (Mac OS X中至少是(旧)BSD版本)不允许在 r 命令(即清理过滤器的 sed 程序中的 ankhsvnsection 之后的空格)添加,更改或删除过滤器后,您可能需要触摸 ,修改,修改或删除过滤器。 或者在Git应用过滤器之前删除你的工作树文件。 Git的索引记录工作树文件的修改时间;如果它们没有改变,那么Git会把 git checkout -file git add file 转换为no-op 。

    如果你想查看索引的实际内容(例如检查清理过滤器产生的内容),可以使用 git show: 0:路径/从/回购/根/到/文件。您通常不能使用 git diff ,因为它也应用了过滤器。



    / b>

      git config filter.SourceControlProvider.smudgesed -e'/ GlobalSection(SubversionScc)/,/ EndGlobalSection / d'
    git config filter.SourceControlProvider.cleansed -e'/ ^ Global \ $ / r ankhsvnsection'


    I want to apply this filter in my git repository to remove a section from a solution file during checkout and to add this section during commit.

    This is the section i want to remove or add:

    GlobalSection(SubversionScc) = preSolution
        Svn-Managed = True
        Manager = AnkhSVN - Subversion Support for Visual Studio
    EndGlobalSection
    

    I have setup this filter in my .git/info/attributes

    *.sln filter=SourceControlProvider

    and i have added these commands to my config

    $ git config filter.SourceControlProvider.smudge "sed -e '/GlobalSection(SubversionScc)/,/EndGlobalSection/d' %"
    $ git config filter.SourceControlProvider.clean "sed -n -e '/^Global$/ r ankhsvnsection ' < %"
    

    Well, it does not work. What have i done wrong?

    ankhsvnsection is a text file that lies in the same directory as the *.sln file

    解决方案

    I see a few issues here:

    1. You have % at the end of both filters.
      This has no special meaning and will be passed as an extra argument to sed, which will probably generate an error (unless you have a file named %).
      Filters should be "streaming" (read from stdin and write to stdout). Their definition can include %f, but it should not really be treated as a file to read or write; Git does that part, filters should just read from stdin and write to stdout.

    2. Your clean filter tries to redirect stdin from %f.
      The input data will already be on stdin, there is no need to redirect.

    3. The sed program in the clean filter uses the r command to access another file.
      Filters seem to be run from root of the working tree, but I am not sure if that is guaranteed.

    4. The sed command in the clean filter uses -n. Its only output will be the contents of the ankhsvnsection file (assuming the input has a Global line).

    5. Some versions of sed (at least the (old) BSD version in Mac OS X) do not allow whitespace after the filename of the r command (i.e. the space after ankhsvnsection in the clean filter’s sed program).

    After adding, changing, or removing a filter you will probably need to touch, modify, or delete your working tree files before Git will apply the filter. Git’s index records the modification time of working tree files; if they have not changed, then Git will translate git checkout -- file and git add file into a no-op.

    If you want to see the actual contents of the index (e.g. to check what the clean filter produced), you can use git show :0:path/from/repo/root/to/file. You can not usually use git diff for this since it also applies the filters.

    These worked for me:

    git config filter.SourceControlProvider.smudge "sed -e '/GlobalSection(SubversionScc)/,/EndGlobalSection/d'"
    git config filter.SourceControlProvider.clean "sed -e '/^Global\$/ r ankhsvnsection'"
    

    这篇关于这个git smudge / clean过滤器有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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