4

I have a repo on github that I am working out of and I often have comments on my .py files that starts with the "# TODO:" to keep a personal note of things to be done.

# TODO: do this <code>

I obviously do not want that to go in a commit.

I want GitHub to search all the files when I am about to commit them and not include lines that start with # TODO:

Does Git already do this? I know certain version control like perforce already have this feature.

Any thoughts?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 6
    You obviously **want** that in your commit. So that if you lose your working copy, you still have the list of all you need to do. So that colleagues know that something needs to be done. So that if you work on another machine, you can know what needs to be done. They're comment on the code. Comments are useful, especially such comments. – JB Nizet Jun 19 '15 at 19:07

1 Answers1

0

I want GitHub to search all the files when I am about to commit them and not include lines that start with # TODO:

GitHub (server side) won't do that.

But you can, in your local repo, register a content filter driver which will do that for you on git commit (like a sed '/^# TODO:/ d').

https://i.stack.imgur.com/EQiwd.png

(image shown in "Customizing Git - Git Attributes", from "Pro Git book")

A 'clean' filter can filter out those lines (I won't discuss if you should leave them or not), and that filter will apply automatically on git commit.
That would obviously remove all TODO including ones left by others, so handle this with care: it is technically possible, but you have to determine if it is needed/useful in your case.


Update February 2016: with git 2.8, even if you had defined a git content filter, you can git add punctually without applying the clean filter if needed:

See commit 1a8630d (29 Jan 2016) by Lars Schneider (larsxschneider).
(Merged by Junio C Hamano -- gitster -- in commit a3764e7, 10 Feb 2016)

convert: treat an empty string for clean/smudge filters as "cat"

git -c filter.myFilter.clean= add test.disable
                            ^^
                          (empty value)
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Keep in mind that if anyone modifies the file in any way, and then you check out that file, your comments will be lost, of course. – David Deutsch Jun 19 '15 at 19:12
  • @DavidDeutsch I agree. My answer was more to point out it is technically possible. Is it actually a good policy to enforce is another question... – VonC Jun 19 '15 at 19:19