我有以下命令,我想通过“makefile”用一个命令执行,我该怎么做?
1. git tag -a v0.0.1 -m "new release"
2. git push origin v0.0.1
现在我已经为开始创建了一些东西
git:
git add .
git commit -m "$m"
git push origin master
现在我有两个问题,如何解决版本问题,例如 这是 v0.0.1,但对于每个新版本,我都需要像首先一样对其进行修改 v0.0.1,下一个版本应该是 v0.0.2,它能以某种方式自动完成吗(也许有一些计数器...)?如果不是,可以将它作为参数添加到一个命令中
- git tag -a v0.0.1 -m "新版本"
- git push origin v0.0.1
更新
下面的答案看起来不错
git describe --tags --abbrev=0 | awk -F. '{$NF+=1; OFS="."; print $0}'
但是我应该如何将它与 结合起来呢?
- git tag -a v0.0.1 -m "新版本"
- git push origin v0.0.1
更新 2
当我按照凯文回答中的建议尝试以下操作时,出现错误:
.PHONY: git
版本=git describe --tags --abbrev=0 | awk-F。 '{$NF+=1; OFS=".";打印 $0}'
git:
git add .
git commit -m "$m"
git push origin master
git tag -a $(VERSION) -m "new release"
git push origin $(VERSION)
错误是: fatal: tag 'ERSION' already exists
似乎是不工作的颠簸,它以某种方式从版本中删除了 v
我做了另一次检查,删除了 repo 并从头开始手动启动第一个版本 0.0.1
现在我确实更改了一个文件并运行脚本,版本现在应该是 0.0.2
如果它成功,但我没有收到错误 fatal: tag 'v0.0.1' already exists
这解释了 bump 不工作,知道为什么吗?
我猜这与这段代码有关 `'{$NF+=1; OFS=".";打印 $0}'
最佳答案
使用最后推送的标签你可以自动增加你的版本号:
git describe --tags --abbrev=0 | awk -F. '{OFS="."; $NF+=1; print $0}'
请记住,您将它存储在一个变量中并使用它来tag
和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
说明:
git describe - 显示可从提交访问的最新标签
--tags - 启用匹配轻量级(未注释)标签。
--abbrev=0 - 将抑制长格式,只显示最接近的标签。
awk -F. - 使用“.”的进程模式作为分隔符
'{OFS="."; $NF+=1;打印 $0}' - 仅增加最后一个数字并加入“。”
makefile :
.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)
关于linux - shell脚本-bump版本自动git,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49655467/