Git Hook更新包JSON版本 [英] Git hook update package json version

查看:107
本文介绍了Git Hook更新包JSON版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们经常忘记更新Package.json文件中的版本号.我们的是AngularJS项目.在包JSON文件中,我们指定以下两个版本信息

In our project we often forget to update version numbers in Package.json file. Ours is a AngularJS project. In our package JSON file we are specifying the below two version information

"version": "1.0.7",
"devVersion": "1.0.4"

在合并分支以进行开发之前,我希望使用自动化脚本来更新以上两个版本号.我认为Git Hooks会帮助我.

Before Merging a branch to develop I want a automated script to update these above two version numbers. I am thinking Git Hooks will help me.

在哪里可以找到挂钩,我可以在本地仓库中的.git文件夹下看到挂钩.我很困惑使用哪个钩子.在Google上搜索建议我必须在服务器上创建钩子.

Where can i find the hooks, I am able to see the hooks in my local repo under .git folder. I am confused which hook to use. Searching on Google suggests I have to create hooks on server.

我在哪里可以找到它们,并且可以更新上述两个键(版本和devVersion)吗?

Where can i find them and can i update the above both keys (version and devVersion) ?

建议使用的位置和挂钩,这将解决很多问题.

Pls suggest the location and hook to use, this will solve a lot of problem.

推荐答案

您有两种挂钩(都存在于任何.git/hooks文件夹中):服务器和客户端挂钩.
它们列在"自定义Git-Git挂钩 "

You have two kinds of hooks (both present in any .git/hooks folder): server and client hooks.
They are listed in "Customizing Git - Git Hooks"

合并是一项本地操作,因此,如果您想在合并期间自动执行任何流程,则需要一个客户端钩子,例如post-commit钩子(意思是在创建合并后的后执行提交).
如果您需要在合并之前 更新该文件,则可以尝试使用pre-commit钩子,然后检查是否合并正在进行中(否则,您的pre-commit钩子将什么都不做,因为您只想在合并之前更新版本).

A merge is a local operation, so if you wanted to automate any process during a merge, you would need a client hook, like a post-commit hook (meaning executed just after creating a merge commit).
If you need to update that file before a merge, you can try a pre-commit hook, and check if a merge is in progress (if not, your pre-commit hook would do nothing since you want to update the versions only before a merge).

您可以在此答案中看到

You can see in this answer an example of a post-commit hook which generates a version.json file.
If is written in node, but you can write a hook ni any scripting language you want.

这篇关于Git Hook更新包JSON版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆