加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – Git Clean Filter打破空文件

发布时间:2020-12-14 01:43:40 所属栏目:Linux 来源:网络整理
导读:我从 Git Attributes文档中设置了以下过滤器: git config filter.dater.smudge expand_dategit config filter.dater.clean 'perl -pe s/$Date[^$]*$/$Date$/"' 现在我运行以下命令: touch nfile.txtgit add --all 并得到以下错误: error:
我从 Git Attributes文档中设置了以下过滤器:

git config filter.dater.smudge expand_date
git config filter.dater.clean 'perl -pe s/$Date[^$]*$/$Date$/"'

现在我运行以下命令:

touch nfile.txt
git add --all

并得到以下错误:

error: copy-fd: read returned Bad file descriptor
error: cannot feed the input to external filter perl -pe "s/$DATE[^$]*$/$DATE$/"
error: external filter perl -pe "s/$DATE[^$]*$/$DATE$/" failed

该错误似乎与我的脚本无关,因为如果我运行此错误,则不会出现错误:

cat nfile.txt | perl -pe "s/$DATE[^$]*$/$DATE$/"

此外,this old thread提到该错误可能是由于“apply_filter中调用的代码中的copy_fd”,并建议在git核心文件convert.c中修补函数filter_buffer_or_fd.就个人而言,如果我可以避免修补核心Git代码,我会非常高兴.

我需要清理错误消息,因为我不希望用户在提交的暂存阶段看到这种丑陋的输出.有办法避免这种情况吗?或者正确处理这种情况的方法?

如果之前已经回答过,我道歉.我在交换或互联网上找不到相同的文章.

解决方法

当使用干净/污迹内容过滤器驱动程序处理时,Git 2.5应该对空文件更加健壮.

请参见2015年5月18日Jim Hill (jthill)到Jim Hill (jthill).
(于2015年6月1日commit 152722f Junio C Hamano — gitster —合并)

sha1_file: pass empty buffer to index empty file

git add of an empty file with a filter pops complaints from copy_fd about a bad file descriptor.

评论简洁:

The clean/smudge interface did not work well when filtering an empty contents (failed and then passed the empty input through). It can be argued that a filter that produces anything but empty for an empty input is nonsense,but if the user wants to do strange things,then why not?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读