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代码,我会非常高兴.
我需要清理错误消息,因为我不希望用户在提交的暂存阶段看到这种丑陋的输出.有办法避免这种情况吗?或者正确处理这种情况的方法?
如果之前已经回答过,我道歉.我在交换或互联网上找不到相同的文章.
解决方法
请参见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 fromcopy_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?