git可以忽略特定的行吗? [英] Can git ignore a specific line?

查看:157
本文介绍了git可以忽略特定的行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用git在电话本机浏览器上进行测试时同步到phonegap。因此,我有以下行:

  var isPhoneGap = false; 

显然我在修改时会改变它,但是有什么办法可以让git忽略这个或者我必须去把它放在它自己的文件中,并忽略它?

我使用Gitx和OSX 10.6上的终端。

解决方案

如果您的文件属于特定类型,则可以声明内容过滤器驱动程序,您可以在 .gitattributes 文件中声明(如 Git Attributes ):



  *。yourType filter = yourFilterName 

(您甚至可以为特定文件设置该过滤器

执行:



git status ,但它的签出版本对于 isPhoneGap 来说是正确的。


I'm using git to sync to phonegap while testing on the phone's native browser. As such I have the following line:

var isPhoneGap = false;

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 .gitattributes file (as presented in the "Keyword expansion" of "Git Attributes"):

*.yourType filter=yourFilterName

(you can even set that filter for a specific file, if you want)

Implement:

  • 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/"'
    

Your file would appear unchanged on git status, yet its checked out version would have the right value for isPhoneGap.

这篇关于git可以忽略特定的行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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