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:
To ignore some special lines in git you need to:
- Create a
.gitattributes
in your repository (remember that.gitattributes
will 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*.rb
files) - 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:
Happy hacking!