Issue
I've the following command which I want to execute with one command via 'makefile' how can I do it ?
1. git tag -a v0.0.1 -m "new release"
2. git push origin v0.0.1
Now I've created something for start
git:
git add .
git commit -m "$m"
git push origin master
Now I've two issue, how to resolve the version e.g. Here is v0.0.1 but for each new release I need to bump it like first is v0.0.1 and the next release should be v0.0.2, can it be done somehow automatically (maybe have some counter...)? if not maybe add it as parameter to one command
- git tag -a v0.0.1 -m "new release"
- git push origin v0.0.1
update
There is answer which looks good with the following
git describe --tags --abbrev=0 | awk -F. '{$NF+=1; OFS="."; print $0}'
but How should I combine it with ?
- git tag -a v0.0.1 -m "new release"
- git push origin v0.0.1
update 2
When I try the following as suggest in Kevin answer I got error:
.PHONY: git
VERSION=git describe --tags --abbrev=0 | awk -F. '{$NF+=1; OFS="."; print $0}'
git:
git add .
git commit -m "$m"
git push origin master
git tag -a $(VERSION) -m "new release"
git push origin $(VERSION)
The error is: fatal: tag 'ERSION' already exists
it seems that the bump of not working and it somehow remove the v
from version
I did another check, remove the repo and start it from scratch manually for the first release 0.0.1
now I did change in one file and run the script , the version should now be 0.0.2
if it success, but no Im getting error fatal: tag 'v0.0.1' already exists
which explain that the bump is not working, any idea why ?
I guess it's related to this code `'{$NF+=1; OFS="."; print $0}'
Solution
Using the last pushed tag you could automatically increment your version number:
git describe --tags --abbrev=0 | awk -F. '{OFS="."; $NF+=1; print $0}'
Keep in mind that you store it in a variable and use it to tag
and push
:
VERSION=`git describe --tags --abbrev=0 | awk -F. '{OFS="."; $NF+=1; print $0}'`
git tag -a $VERSION -m "new release"
git push origin $VERSION
Explanation:
git describe - Show the most recent tag that is reachable from a commit
--tags - Enables matching a lightweight (non-annotated) tag.
--abbrev=0 - Will suppress long format, only showing the closest tag.
awk -F. - Process pattern using "." as a delimiter
'{OFS="."; $NF+=1; print $0}' - only increment last number and join with "."
.PHONY: git
git:
$(eval VERSION=$(shell git describe --tags --abbrev=0 | awk -F. '{OFS="."; $$NF+=1; print $0}'))
git add .
git commit -m "$m"
git push origin master
git tag -a $(VERSION) -m "new release"
git push origin $(VERSION)
Answered By - Kevin Sandow