202

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 ''

1
  • I know this was an old question, but what operating system was you interested about? Somebody replied mentionig Windows about first answer, for example. Are you using Linux? Maybe nice to clarify in the question that you want a system-independent solution or something like that Commented Jun 29, 2023 at 13:55

5 Answers 5

341
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 Linux / git bash / Windows bash you could do:

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

and on Windows:

for /f "delims=" %a in ('git describe --tags --abbrev^=0') do @set latesttag=%a git log %latesttag%..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.

Sign up to request clarification or add additional context in comments.

9 Comments

--oneline should be before <yourlasttag>..HEAD. Also, @ is short for HEAD. Using $() may be preferable to using backticks.
@A-B-B there is no difference if --oneline is before or after. I would also prefer HEAD even if there is a shorthand, as it is easier to understand and more widely known.
and I see no benefit in using $() in this context. Maybe you have thought of some.
Is there a concise one-liner which can also handle cases where there may be no prior tag on the branch? It should just default to outputting the entire commit history for the branch.
In Powershell, wrap the git log argument in quotes: git log "$(git describe --tags --abbrev=0)..HEAD" --oneline
|
70

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.

1 Comment

nice!, if just want the commits text change --oneline to --pretty=format:"%s": git log --pretty=format:"%s" $(git describe --tags --abbrev=0 @^)..@
2

You can easily omit Merge commits with sed

git log $(git describe --tags --abbrev=0)..@ --oneline | sed '/Merge/d' 

1 Comment

Note that there is a dedicated option to do that and it's called --no-merges.
1

As an addition to this answer, to omit merge commits, one can use

git log <tag>..HEAD --oneline --no-merges 

as mentioned in this other answer

Comments

-1

Newest tag across all branches

newestTaggedCommit="$(git rev-list --tags --max-count=1)" tagName="$(git describe --tags "$newestTaggedCommit")" # Commits since tag git log "$(git rev-list --tags --max-count=1)"..HEAD --oneline 

https://stackoverflow.com/a/7979255

git rev-list --tags seems reliable for my use case, finding the latest release tag. We release from different branches.

Newest tag on current branch

newestTagName="$(git describe --tags --abbrev=0)" # Commits since tag git log "$(git describe --tags --abbrev=0)"..HEAD --oneline 

https://stackoverflow.com/a/12083016

git describe should look for the latest tag in both parent branches of a merge, if --first-parent isn't specified.

Jira issues merged since last tag

In case you, like me, came here for an overview of commits included in a release..

This script lists commits since the last (release) tag, for multiple repositories. If you added Jira keys in commit message titles, it opens a list of merged issues in Jira.

#!/bin/bash # Config jiraSearchUrl='https://jira.my.org/issues/?jql=' jiraProjectKey='MYAPP' localRepoDirs=( '/c/coding on windows/frontend' '../../projects/full stack app/'* ) for repo in "${localRepoDirs[@]}"; do echo; echo; echo '**** To ************************ from ****' pushd "$repo" || exit newestTaggedCommit="$(git rev-list --tags --max-count=1)" lastTag="$(git describe --tags "$newestTaggedCommit")" # Or get newest tag only from checked out branch: # lastTag=$(git describe --tags --abbrev=0) # Or enter a tag (and e.g. checkout the next tag for an overview of that release): # lastTag='my-app-9.0.0.0' echo; echo "- Commits on current branch, not yet included in $lastTag :" commits=$(git log "$lastTag"..HEAD --oneline) echo "$commits"; echo echo "- Jira keys in commit message titles, since tag $lastTag :" readarray -t jiras < <(echo "$commits" | grep -E --only-matching "$jiraProjectKey-[0-9]+" | sort -u) echo "${jiras[@]}"; echo allJiras+=( "${jiras[@]}" ) popd || exit done jqlFilter="$(IFS=, ; echo "key in (${allJiras[*]})")" filterUrl="$jiraSearchUrl""$jqlFilter" echo; echo; echo '************************************************' echo 'All merged Jira issues:' echo "$filterUrl" echo '************************************************'; echo # Open in Windows default browser start "" "$filterUrl" 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.