Antonio Antonio - 1 month ago 9
Git Question

How do I tell .gitignore (or git itself) to ignore lines containing # TODO

I have a lot of lines with

for future references. These are personal, and I'd like to not commit them along with the rest of my file when I make changes.

Is there any way to tell .gitignore (or git itself) to not include any line containing

Or as a bonus.. Not just the line, but maybe from the
to the end of line incase I have a
on the same line there is code


def destroy
# TODO Alter route (Tell git to ignore this)


def destroy
@comment.destroy # TODO Alter this line. (Tell git to ignore from '# TODO' onwards.


You could use a 'clean' filter. It is run before a file is staged.

First, define the file types that you want to use the filter for, and put them in your .gitattributes file:

.rb filter=removetodo

Then, adjust your config so that you tell git what the "removetodo" filter is supposed to do on clean:

git config filter.removetodo.clean "sed '/TODO/d'"

sed command taken from Delete lines in a text file that containing a specific string

Then, when you do a git add, git will silently remove every line containing the word TODO from your .rb files, without affecting your working area.

The downside is that you will loose all your TODO's if you accidentally merge in any changes that touch these files.