SystematicFrank SystematicFrank - 1 month ago 11
Git Question

Filter git log to show only commits with notes

How can I dump a log of my commits showing only the ones with notes of a given namespace?

Commits without notes, or notes not belonging to a given namespace should be filtered out

In the text dump I do not want just the note, also the commit info.

I have played with: show refs/notes/ and I believe the solution might be there rather than with "git log". However I am still having some problems to find the right command showing also all commits.

Answer

git notes will give you the id of each note and what object it applies to. So the second column is what you want.

$ git notes
f5ac8874676de3029ffc8c31935644ff7c4deae0 07ca160c58cf259fe8bb5e87b9d9a7cbf8845f87
62ecfc95355587d6d1f779fcaca6e4f53d088ccc eb6c60b9dcb56219d9d882759c0bf928f6d6c3fa

Grab that last column using cut and pass them into git show.

$ git notes | cut -d' ' -f2 | xargs git show

To pick a specific namespace, add a --ref=namesapce to git notes.

$ git notes --ref=namespace | cut -d' ' -f2 | xargs git show

There's a slight problem here, git show will show the current checkout if passed no arguments. So if there's no notes you're going to get misleading output. I leave this as an exercise to write a more interesting program to fix that.