Ignore file lines in git
14 Nov 2015For example, you have this code and you want to ignore in git lines which contain username and password values:
def ssh_connect
username = "root" # ignore this line
password = "password" # ignore this line too
ip = "192.168.1.1"
# ...
endTo ignore some special lines in git you need to:
- Create a
.gitattributesin your repository (remember that.gitattributeswill be committed into the repository, if you don’t want that, add it to.git/info/attributes) - Add
*.rb filter=ignoreline(run filter named ignoreline on all*.rbfiles) - Now, we need to define ignoreline filter in
.gitconfig git config --global filter.ignoreline.clean "sed '/#ignoreline$/'d"(delete theses lines)git config --global filter.ignoreline.smudge cat(do nothing when pulling file from the repository)
And then, you can ignore some lines using #ignoreline comment:
def ssh_connect
username = "root" #ignoreline
password = "password" #ignoreline
ip = "192.168.1.1"
# ...
endHappy hacking!