How to list all my TODO messages in the current git managed code base

南楼画角 提交于 2019-11-29 21:49:42

You can combine git blame with grep.

Like this (not the best one, but should work)

git grep -l TODO | xargs -n1 git blame | grep 'Your name' | grep TODO

Improved versions might combine line numbers found by first grep with git blame's ability to show only given lines.

I want do add on aragaer's and Kyle's solution:

  • use grep config to get your name
  • displaying the file name and the line number of the TODO comment
  • removing the commit SHA, the author's name and the commit timestamp
git grep -l TODO | xargs -n1 git blame -f -n -w | grep "$(git config user.name)" | grep TODO | sed "s/.\{9\}//" | sed "s/(.*)[[:space:]]*//"

This prints:

Cpp/CoolClass.cpp 123 //TODO: Do we really need this?
Cpp/AnotherClass.cpp 42 //TODO: Do we miss something?
Java/MyListener.java 23 //TODO: Optimize

I found that the user name can have spaces, so it's easier to filter by email address. Also, the @todo (lowercase) is my way of adding notes in docblocks, so I added the "ignore lower/upper case" flag. This is my solution:

git grep -il TODO | xargs -n1 git blame -M  -f -e | grep -i TODO | grep $(git config user.email)

Complete with using git config to get your name:

git grep -l TODO | xargs -n1 git blame | grep "$(git config user.name)" | grep TODO

Small suggestion here that I just ran across, larger repo and some binary files. The xargs -ni git blame section was causing an unexpected term with signal 13. I got around this by adding a -I switch on the initial git grep.

FWIW here's full error (go go google)

xargs: git: terminated by signal 13

Here's an example I used (also removed grep for my mine as wanted to see all)

git grep -I -l TODO | xargs -n1 git blame -f -n -w | grep TODO | sed "s/.\{9\}//" | sed "s/(.*)[[:space:]]*//"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!