Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filter git log to show only commits with notes

Tags:

git

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.

like image 359
SystematicFrank Avatar asked Oct 29 '12 08:10

SystematicFrank


1 Answers

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)" = "" ] || git notes \
| cut -d' ' -f2 \
| xargs git show

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

[ "$(git notes --ref=namespace)" = "" ] || git notes --ref=namespace \
| cut -d' ' -f2 
| xargs git show

The initial test, [...], prevents a slight problem: git show will show the current checkout if passed no arguments. So if there's no notes you're going to get misleading output. With the initial test that's not a problem: if the test fails, i.e., if there's no notes, then git show won't be called.

like image 90
Schwern Avatar answered Nov 06 '22 04:11

Schwern