Git始终忽略特定文件的某一行内容

笔者在编写Z Shell文件的时候经常会使用到set -x来开启调试,但不希望提交到仓库

解决方案

Git提供了一种文件过滤器,此方法可以帮助在提交时移除set -x
我们先来编写脚本,如何移除这一行。
即使用sed "/^set -x$/d"

给过滤器起一个名字,这里以“DebugShell”为例。添加过滤器

git config --local filter.DebugShell.clean 'sed "/^set -x$/d"'
git config --local filter.DebugShell. smudge 'sed "/^set -x$/d"'

修改.gitattributes文件,对特定文件使用过滤器。

*.zsh filter=DebugShell

猜你喜欢

转载自www.cnblogs.com/zhuxiaoxi/p/11759319.html