Can git filter out specific lines before committing?
I have a github repo that I work from, and I often have comments on my files .py
that start with " # TODO:
" to leave a personal note on what to do.
# TODO: do this <code>
I obviously don't want this to happen in the commit.
I want GitHub to go through all the files when I am about to commit them, and not include the lines starting with # TODO:
Does Git already do this? I know that some version controls like perforce already have this feature.
Any thoughts?
source to share
I want GitHub to go through all the files when I am about to commit them, and not include the lines starting with
# TODO:
GitHub (server side) won't do this.
But you can register a content filter filter in your local repo that will do this for you on ( like a ). git commit
sed '/^# TODO:/ d'
(image shown in Configuring Git - Git Attributes ", from" Pro Git book ")
Update Feb 2016: With Git 2.8, even if you have defined a Git content filter, you can add Git pointwise without applying a pure filter:
See commit 1a8630d (29 Jan 2016) by Lars Schneider ( larsxschneider
) .
(merge Junio ββC Hamano - gitster
- in commit a3764e7 , Feb 10, 2016)
convert
: treat empty string for clean / smudge filters as "cat
"
git -c filter.myFilter.clean= add test.disable
^^
(empty value)
source to share