Find newly added TODO comments in staged and unstaged Git changes and print them as:
relative/path/to/file:line
By default, changes are compared against HEAD. You can optionally pass another Git revision or branch.
git todoCompare against HEAD:
git todoCompare against another revision:
git todo master
git todo main
git todo origin/main
git todo HEAD~3For example:
git todo masterfinds TODOs added in your current working tree compared with master.
Add this to ~/.gitconfig:
[alias]
todo = "!f() { ref=\"${1:-HEAD}\"; git diff \"$ref\" --unified=0 | awk 'BEGIN{IGNORECASE=1} /^\\+\\+\\+ b\\//{f=substr($0,7)} /^@@/{match($0,/\\+[0-9]+/); n=substr($0,RSTART+1,RLENGTH-1)-1; next} /^\\+/{n++; if ($0 ~ /(\\/\\/|#)[[:space:]]*todo/) print f \":\" n}'; }; f"Then run:
git todoor:
git todo masterThe search is case-insensitive and recognises both // and # comments:
// TODO
//TODO
// todo
# TODO
#todo
Assets/Scripts/Entity/Player.cs:171
Assets/Scripts/Settings/GlobalSettings.cs:745
scripts/build.sh:32
git todocompares againstHEAD.git todo <revision>compares against the specified revision.- Includes both staged and unstaged tracked changes.
- Does not include untracked files.
- Reports only added lines from the diff.
- Output uses repository-relative paths with line numbers.