Get all git commits since last tag

GitVersion Control

Git Problem Overview


When I'm going to tag a commit, I need to know what changed since the last tagged commit. Eg:

a87a6sdf87a6d4 Some new feature
a87a6sdf87a6d3 Some bug fix
a87a6sdf87a6d2 Some comments added
a87a6sdf87a6d1 Some merge <- v1.4.0

In this example I would like to know about the 3 newest commits, or be able to print a log like above, that shows both commits their tags if any. And when I see there has been a new feature added, I would tag it v1.5.0.

How do you deal with this? Is this how I'm supposed to use tags? What should I write in the tag message? I always leave it blank: git tag -a v1.2.3 -m ''

Git Solutions


Solution 1 - Git

git log <yourlasttag>..HEAD

If you want them like in your example, on the one line with commit id + message, then

git log <yourlasttag>..HEAD --oneline

and in case you don't know your latest tag or want this to be dynamic, on windows you could do

for /f "delims=" %a in ('git describe --tags --abbrev^=0') do @set latesttag=%a
git log %latesttag%..HEAD --oneline

and on linux / git bash / windows bash

git log $(git describe --tags --abbrev=0)..HEAD --oneline

Also, if you have a case where you know a tag in history and want to print everything from that tag up to current situation, you might want to add also --decorate so it would print out any tags in between.

Solution 2 - Git

If your current commit is also a tag and you want to dynamically get the changes since the previous tag, without knowing the latest tag nor previous tag name, you can do:

git log --oneline $(git describe --tags --abbrev=0 @^)..@

Note that @ is short for HEAD.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChocoDeveloperView Question on Stackoverflow
Solution 1 - GiteisView Answer on Stackoverflow
Solution 2 - GitmediafreakchView Answer on Stackoverflow