HBuilderX技巧:Git插件,手把手教你扩展git命令

官方的git插件,只是列出了常用的git命令,并不涵盖所有。

遇到缺失的怎么办?

小编教您如何扩展git命令

git插件配置入口在哪里?

如下图片所示,点击最后一个【插件配置】,即打开git插件配置文件package.json

解析GIT命令菜单

{
        "id":"GIT_TAG",                          // Git命令ID
        "name":"git tag",                         // 外部命令显示的名称
        "command":["git", "tag"],             // 命令,参数使用逗号分割即可
        "workingDir":"${projectDir}",       // 工作目录,一般两个参数 ${projectDir}: 项目目录;${file}:文件 workingDir也可以省略
        "key":"",            // 快捷键
        "showInParentMenu":false,       // 是否显示在上一级菜单中,默认false
        "onDidSaveExecution": false,    // 是否保存时执行,默认false
        "type":"terminal"                        // 默认terminal
      }

如上解说,只需要配置一个id、name、command,就可以组成一个新的命令

特别说明:

比如切换分支、创建tag、创建分支,都需要输入啊,别担心。

在命令中加上${userInput},就可以调起一个输入框。如下

"command":["git", "tag", "${userInput:请输入tag名称}"]

示例: git tag示例

比如git tag是一个比较重要的操作,官方没提供,那我们自己手动加上吧

例子1: 打tag标签

{
        "id":"GIT_TAG_CREATE",
        "name":"git tag 打标签",
        "command":["git", "tag", "${userInput:请输入tag名称}"],
        "workingDir":"${projectDir}",
        "key":"",
        "showInParentMenu":false,
        "onDidSaveExecution": false,
        "type":"terminal"
      }

例子2:git show查看标签信息

{
        "id":"GIT_SHOW",
        "name":"git show 查看标签信息",
        "command":["git", "show","${userInput:请输入要查看的tag名称}"],
        "workingDir":"${projectDir}",
        "key":"",
        "showInParentMenu":false,
        "onDidSaveExecution": false,
        "type":"terminal"
      }

例子3:git tag 查看标签列表

{
        "id":"GIT_TAG_LIST",
        "name":"git tag 查看标签列表",
        "command":["git", "tag"],
        "workingDir":"${projectDir}",
        "key":"",
        "showInParentMenu":false,
        "onDidSaveExecution": false,
        "type":"terminal"
      },

例子4: git reset 回退到指定版本

{
        "id":"GIT_RESET_COMMIT",
        "name":"git reset 回退到指定版本",
        "command":["git", "reset", "--hard", "${userInput:请输入commit id}"],
        "workingDir":"${projectDir}",
        "key":"",
        "showInParentMenu":false,
        "onDidSaveExecution": false,
        "type":"terminal"
      }

注意事项

编辑插件配置后,并不能马上生效,需要重启软件。
请大家将自己修改后的配置文件,另存一份,以防更新后丢失。

git配置文件

小编将自己的git配置文件,放到github上了,请大家关注

https://github.com/yi-heng/MyConfig/blob/master/HBuilderX/git%E6%8F%92%E4%BB%B6%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6.json

标签:GIT 发布于:2019-10-17 15:26:34