In our projects we use bitbucket repositories and we use TAGs to identify the versions where release has taken place. Is there a way to identify the tag after which a new release branch was created.
Asked
Active
Viewed 53 times
2 Answers
1
The latest tag on a given branch can be found with git describe
.
git describe --tags <branch_name>
Diagram:
A - B - C - D - E - F - G - H - I (my_branch)
^ ^
|- Tag 'foo' |
|- Tag 'bar'
Example:
git describe --tags my_branch
Complete Example
(Note: labels don't match the diagram exactly)
❯ git init
Initialized empty Git repository in /private/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1/.git/
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git commit --allow-empty -m "A"
[master (root-commit) d29d846] A
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git commit --allow-empty -m "B"
[master 33eed45] B
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git tag v0.0.1
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git commit --allow-empty -m "C"
[master cd6d882] C
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git commit --allow-empty -m "D"
[master 420558f] D
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git tag v0.0.2
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 master
❯ git checkout -b my_branch
Switched to a new branch 'my_branch'
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 my_branch
❯ git commit --allow-empty -m "E"
[my_branch d4d421d] E
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 my_branch
❯ git commit --allow-empty -m "D"
[my_branch 08edc95] D
/var/folders/bd/9y15j5cd4qd80vgfbsp6b67r0000gp/T/tmp.KnhXdwv1 my_branch
❯ git describe --tags my_branch
v0.0.2-2-g08edc95

Unapiedra
- 15,037
- 12
- 64
- 93
-
You can use this with anything that identifies a commit (not just a branch name). If you have the sha1 of the fork point when the branch was created, `git describe --tags sha1` will work too. – LeGEC Jul 09 '20 at 07:40
0
git tag --merged <branch name>
Should list all tags reachable by that branch. The most recent tag usually is to be found on the top.
You could refine that by only showing release tags (e.g. filtering by "release") and by only first line, e.g.
git tag --merged <branch name> | grep -m1 -i release
Note: This doesn't care about actual branch creation, but about which tags can be reached via the given branch. So if a branch had been created after 0.1 but the release 0.2 was later merged into the branch, then the 0.2 tag should show up.

Jay
- 3,640
- 12
- 17