gittodo

Use git to list TODOs in code sorted by date introduced


I would like to display a list of all TODOs I have in my code, but sorted by using the history (Git) and showing the most recent first.

Kind of like the result displayed here: git – order commits introducing "TODO"s by date

But showing the lines of the TODOs, not the hashes.

Should look like this:

Fri May 22 11:22:27 2015 +0200 - // TODO: Refactor this code
Fri Apr 25 17:32:13 2014 +0200 - // TODO: We should remove this when tests pass
Sat Mar 29 23:11:39 2014 +0100 - // TODO: Rename to FooBar

I don't think git log can show that, but I'm not sure and I don't have the Git CLI mojo to figure this out myself. Any idea?


Solution

  • Here is an approximate solution; the formatting isn't quite what you've asked for, so you'd need to pipe it through awk or something similar to reorder the fields if that's important.

    git ls-tree -r -z --name-only HEAD -- . | xargs -0 -n1 git blame -c | grep TODO | sort -t\t -k3
    

    It works as follows:

    Note that this ignores the time zone completely (i.e. it just sorts on the raw date without taking account of the +0000 part).