通过npm节点自动执行Git提交+版本控制+标签 [英] Automate Git commit + versioning + tag by npm node

查看:156
本文介绍了通过npm节点自动执行Git提交+版本控制+标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直想得到的是,使用npm版本来更新package.json并创建一个标签,然后提交我的更改.这样,我就可以按版本进行标记,自动进行版本控制并提交信息.

What I have been trying to get is, work with npm version to update the package.json and create a tag and then commit my changes. In this way, I will be able to have tags by version, auto versioning and commit with the info.

我遇到的问题是,当我使用npm版本时,它会自动执行标签+提交,如果您之前进行了一些更改,则无法完成,所以对我来说,增加它没有任何意义项目的版本,然后再进行更改/实现/修复.

The problem I am having is, when I am using npm version, it's doing a tag + commit automatically and then it can not be done if you have previously some changes, So for me, it doesn't make sense to increase the version of your project, before to do the changes/implementation/fixes.

然后,我遇到的另一个问题是,我首先将版本增加为补丁",然后进行一些更改,添加所有内容,然后提交,然后发布,最后我有2个提交,1因为有npm版本补丁,而另一个是好的.

Then, another problem I was having is that I first increase the version as a 'patch', then I do some changes, I add all, I commit and then I publish, at the end, I have 2 commits, 1 because of the npm version patch, and the other one the good one.

我在文档此处中看到,有一个参数可让您禁用此自动标签+提交,但是我真的很想在控制台中使用命令来更新软件包控制台,并将该版本设置为标签.

I saw in the documentation here that there is a parameter that allow you to disable this auto tag + commit, but then I would really like to use a command in the console to be able to update the package console and get that version set up as a tag.

用另一只手,不确定我说的这是否有意义,因为据我所知,当您创建标签时,您可以回到项目中,到那时,我如何假装像那如果我禁用自动提交?

By another hand, not sure if this that I am saying it does make sense because as far as I know, when you create a tag, you can go back in your project to that point, So how I pretend to work like that if I am disabling the auto commit?

最后,我要明确的是我的目标,我真正想要达到的是由节点脚本处理半自动脚本,以便能够 要增加项目的版本,请使用新的 版本,添加所有更改,提交并推送.

Finally, What I want to make clear is my goal, What I really want to reach is handle by node scripts a semi-automated script to be able to increase the version of the project, create a tag with the new version, add all changes, commit and push.

注意:我不想使用gulp-git,因为我认为没有它也可以处理它.

不确定,如果我不够清楚,请询问并帮助我:)

Not sure if I was clear enough, if not, please ask and help me :)

推荐答案

好的,我知道了!我一直在寻找一个简单的命令并自动执行一些无聊的任务,而这些任务我们必须始终按照与Git相同的顺序执行.

Ok guys, I got it! What I was looking for is to run a simple command and automate some boring tasks we have to do always in the same order for Git.

所以,我要做的是,首先运行以下命令:

So, What I do here is, first I run this command:

$> npm run commit -- 'v.1.0.1: Fixes'

发生的事情是,我首先清理了文件夹/文件,而我不需要/想要,然后我运行:

What it happens is that I firstly clean of folders/files and I dont need/want, then I run:

$> npm version patch -no-git-tag-version --force

该命令增加我的package.json版本,而不是提交&不是标签,所以然后我像往常一样添加所有更改,然后提交更改,然后,我使用tag:commit gulp任务创建标签.

That command increase my package.json version, not commit & not tag, So Then I add all changes as normal, then I commit my changes and after this, I create the tag with the tag:commit gulp task.

在gulp任务中(随附),我正在获取带有require的软件包版本并将其视为对象.

In the gulp task (attached bellow), I am getting the version of the package with require and treat it as a object.

"scripts": {
   "start": "gulp start",
   "initialize": "npm install & typings install",
   "clean": "gulp clean:folders",
   "commit:example": "echo 'npm run commit -- 'v.1.0.1: Fixes'",
   "commit:patch": "npm version patch --no-git-tag-version --force",
   "commit:minor": "npm version minor --no-git-tag-version --force",
   "commit:major": "npm version major --no-git-tag-version --force",
   "precommit": "npm run clean && npm run commit:patch && git add --all",
   "postcommit": "gulp tag:commit && git push origin master && git status && gulp commit:done",
   "commit": "git commit -m "
},

然后,我在gulp文件中保存了它:

and then, I have this in my gulp file:

///// ***** GIT ***** /////


gulp.task('tag:commit', function () {
    var version = pjson.version;
    console.log(colors.bgWhite.black.bold(' \nTagging the version ' + version + ' \n'));
    return run('git tag ' + version).exec();
});

我不想使用gulp-git,因为我知道有办法做到这一点,如果我需要合并,创建早午餐或其他任何东西,我将运行控制台并对其进行修复,但对于日常提交,它是痛苦的是要记住标记,更新软件包版本,将其放入git commit....

I didn't want to use gulp-git as I knew there was a way to do that, If I need to merge, create brunch or whatever, I will run the console and fix it, but for daily commits, it's painful to remember to tag, update the package version, put it in the git commit....

我希望这对其他人有用!

I hope that's useful for someone else!

干杯

这篇关于通过npm节点自动执行Git提交+版本控制+标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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