Search code examples
gitdifftagging

how do you list git commits with their tags interleaved in the output?


I have some code that gets lots of commits and is tagged often too.

I would like to see what commits are for each tag and I then I will do a git diff between the tags to see the actual code changes.

how do you list git commits with their tags interleaved in the output?


i was thinking something like this output would allow me to see what commits were for each tag:

${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${tag_name} ${tag_date}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${short_commit_hash} ${commit_date} ${first_line_of_text_from_commit_message}
${tag_name} ${tag_date}

however this output is not a strict requirement. this is just one idea i came up with that would help me see what commits were from each tag.

there may be easy git commands that already do most of what I am asking and those commands might be really easy/straight-forward.


Solution

  • You don't really want the tags interleaved. You want a newline in the log format before the tag. With that in mind, just do:

    git log --format=format:'%h %ci %s%+D'
    

    From the git-log documentation: If you add a + (plus sign) after % of a placeholder, a line-feed is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string.