2

How can I list all TODO comments I ever added or edited within all commits of a git versioned project? I do not want to see everyone else's TODO comments.

The output should print all lines actually containing my TODO comments:

\\TODO: This should be changed to something else
\\TODO I guess the bug hides here
\\ TODO I need to do something here

I do not want to just list the commits themselves as git log -S TODO does.

Lars Blumberg
  • 19,326
  • 11
  • 90
  • 127

1 Answers1

4

If that TODO is in files (as opposed to the commit message), you can do:

git log -p --author=you -S TODO | grep "\+.*TODO"

See more at "How to grep (search) committed code in the git history?".
-p: to see the content as a patch, which allows to grep on the line including the TODO.

However, this lists all TODO comments ever written, even those that already resolved and thus removed again from code.

For a more complete answer, see "How to list all my TODO messages in the current git managed code base":

git grep -l TODO | xargs -n1 git blame -f -n -w | grep "Your name" | grep TODO | sed "s/.\{9\}//" | sed "s/(.*)[[:space:]]*//"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Great, work like a charm. Do you know how I can reduce the TODO comments only to those that *currently exist*? Such as that later on removed TODO comments won't appear? – Lars Blumberg Jul 30 '14 at 12:11
  • @LarsBlumberg Probably by grepping for a '+', like your edit suggests. – VonC Jul 30 '14 at 12:22
  • This still prints TODO comments that one added earlier and then removed during later commits. What I would like to see is all my TODO comments in the current base. – Lars Blumberg Jul 30 '14 at 12:34
  • @LarsBlumberg not easy, because the content of a TODO line might have change between its introduction and its removal. – VonC Jul 30 '14 at 12:48
  • Ok, maybe I need to use another tool chain than `git log`. – Lars Blumberg Jul 30 '14 at 12:58
  • @LarsBlumberg or at least ask a new question, with a link back to this one for reference. – VonC Jul 30 '14 at 12:59
  • Here is it: https://stackoverflow.com/questions/25039242/how-to-list-all-my-todo-messages-in-the-current-git-managed-code-base – Lars Blumberg Jul 30 '14 at 14:36