Before pushing a Git commit, I usually want to review all TODOs that I've added in the code. I've tried several approaches, but I'm still haven't found a good way to do this.
E.g. with the following command, I can see all TODOs added (and removed) in the last commit:
git diff HEAD^ | grep "TODO"
However in this output I don't see which files contained the change so I have to guess or search the corresponding files. With the following command, I see all files with a "TODO" change, but I don't see the actual TODOs:
git diff HEAD^ --name-only -G "TODO"
So my question is how can I both see the diff line and the name of the file containing the difference? Is it e.g. possible to make git diff
prefix every diff line with the file name? Then the grep'ed lines would give have all the information I need.
The following is getting close to what I originally wanted:
git diff HEAD^ --name-only -G "TODO" | xargs git grep "TODO" --
This prints all TODOs in the files touched in the last commit - and not just the TODOs that were added.
But this is also quite useful. In this way I can also check if there may be other TODOs that can now be removed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With