Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all my current TODO messages in a git repository?

Tags:

I want to see all TODO comments that only I wrote and that exist in the current code base that is git managed.

What I've got so far is printing all TODO comments that I've ever created or modified during the complete git history: git log -p --author="My name" -S TODO | grep "\+.*TODO"

But this tool chain lists all TODO comments ever written, even those that I've already resolved and thus removed again from code.

What’s a suitable tool chain that can search the current code base line-by-line, check if it contains "TODO" and if this line was authored by me print those lines?

like image 682
Lars Blumberg Avatar asked Jul 30 '14 14:07

Lars Blumberg


People also ask

How do I see my full git history?

`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.

Where are git commit messages stored?

The file is located in the . git folder, the file is named "COMMIT_EDITMSG". Show activity on this post. This will allow you to modify your commit, as well as your commit message on your local branch.

How do I find my git text repository?

To search the code in all repositories owned by a certain user or organization, you can use the user or org qualifier. To search the code in a specific repository, you can use the repo qualifier. user:defunkt extension:rb matches code from @defunkt that ends in . rb.

What is todo in git?

Use it like so from the command line: todo Check if feature X works under edge-case. This records an empty commit prefixed with "TODO". This way git log will remind you both what you have done on this branch and what you need to be doing: $ git log --oneline master..


2 Answers

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.

like image 94
aragaer Avatar answered Sep 26 '22 03:09

aragaer


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 
like image 35
Lars Blumberg Avatar answered Sep 23 '22 03:09

Lars Blumberg