I have a feature branch that's grown quite large. There are quite a few lingering TODO comments in our code, but I'd like to find all TODOs added to the code (and not removed yet) on commits not yet merged into master. How might I go about that?
You can view all created branches using the git branch command. It will show a list of all branches and mark the current branch with an asterisk and highlight it in green. In a single command, you can create and switch to a new branch right away.
The command to list all commits is git rev- list --remotes `git rev-list` list commit objects in reverse chronological order. The key option is `–remotes`.
If you're doing your housekeeping and git rebase -i the branch every time before you push, git notices that these TODO commits are empty and automatically comments them out from the list of commits to keep. You still get to review the TODO list, but you don't have to worry about cleaning up these commits manually.
You can keep quick, short-lived personal TODOs as empty commits in the current git branch ( original tweet ): <i>You can save this either as a shell function or git-todo executable.</i> 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:
You can use this as an Git alias:
git --no-pager diff -U0 master | \
grep '^+.*TODO' | \
sed 's/^+//' | \
git --no-pager grep -nFf - 2> /dev/null
It shows the added/modified TODO lines of the current branch (compared to master
), but you have to git add
before using it (because of git grep
).
It can be even more usefull if you add it to the status
alias, thus you would be sure that no TODOs remaining when you see the status.
[alias]
s = "!sh -c ' \
[ $GIT_PREFIX ] && cd $GIT_PREFIX; \
git status --short --branch $*; \
git --no-pager diff -U0 master | \
grep \"^+.*TODO\" | \
sed \"s/^+//\" | \
git --no-pager grep -nFf - 2> /dev/null' -"
Example output:
$ git s
## my-branch...origin/my-branch [ahead 2]
M README.adoc
README.adoc:12: // TODO: Add screencast
README.adoc:26: // TODO: Advertise Asciidoctor
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