git可以忽略特定的行吗? [英] Can git ignore a specific line?
问题描述
我正在使用git在电话本机浏览器上进行测试时同步到phonegap。因此,我有以下行:
var isPhoneGap = false;
显然我在修改时会改变它,但是有什么办法可以让git忽略这个或者我必须去把它放在它自己的文件中,并忽略它?
我使用Gitx和OSX 10.6上的终端。
如果您的文件属于特定类型,则可以声明内容过滤器驱动程序,您可以在 .gitattributes
文件中声明(如 Git Attributes ):
*。yourType filter = yourFilterName
(您甚至可以为特定文件设置该过滤器 执行: I'm using git to sync to phonegap while testing on the phone's native browser. As such I have the following line: Obviously I change this when building, but is there any way I can set up git to ignore this one line or do I have to go and put it in its own file and ignore it that way? I'm using Gitx and the terminal on OSX 10.6. If your file is of a specific type, you can declare a content filter driver, that you can declare in a (you can even set that filter for a specific file, if you want) Implement: Your file would appear unchanged on 这篇关于git可以忽略特定的行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
yourFilterName.smudge
(触发于 git checkout
)和
git config --global filter.yourFilterName.smudge'seds / isPhoneGap =。* / isPhoneGap = true /'
$
git add $ c $>触发
yourFilterName.clean
c>)
git config --global filter.yourFilterName.clean'seds / isPhoneGap =。* / isPhoneGap = false /'
git status
,但它的签出版本对于 isPhoneGap
来说是正确的。var isPhoneGap = false;
.gitattributes
file (as presented in the "Keyword expansion" of "Git Attributes"):*.yourType filter=yourFilterName
yourFilterName.smudge
(triggered on git checkout
) and git config --global filter.yourFilterName.smudge 'sed "s/isPhoneGap = .*/isPhoneGap = true/"'
yourFilterName.clean
(triggered on git add
)git config --global filter.yourFilterName.clean 'sed "s/isPhoneGap = .*/isPhoneGap = false/"'
git status
, yet its checked out version would have the right value for isPhoneGap
.