【问题标题】:Is there a way to save all files, commit and upload in one command in Visual Studio Code有没有办法在 Visual Studio Code 中的一个命令中保存所有文件、提交和上传
【发布时间】:2018-08-15 15:10:00
【问题描述】:

我发现自己在我的代码上做了很多修补程序,我必须在远程机器上进行测试。在 Visual Studio 代码中,有没有办法设置一个宏,将

  1. 保存所有打开的文件
  2. 提交更改(使用空白或随机提交消息)
  3. 上传所有提交

谢谢!

【问题讨论】:

    标签: visual-studio-code vscode-settings vscode-tasks


    【解决方案1】:

    不保存文件:

    keybindings.json:

    {
        "key": "ctrl+alt+s",
        "command": "workbench.action.terminal.sendSequence",
        "args": {
            "text": "git add . && git commit -a -m 'Update' && git push\u000D"
        }
    }
    

    关于sendSequencehttps://code.visualstudio.com/docs/editor/integrated-terminal#_send-text-from-a-keybinding


    保存文件:

    MoreThanTomanswer 调整:

    (使用https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command

    settings.json:

    "multiCommand.commands": [
        {
            "command": "multiCommand.syncAllFiles",
            "sequence": [
                "workbench.action.files.saveAll",
                {
                    "command": "workbench.action.terminal.sendSequence",
                    "args": {
                        "text": "git add . && git commit -a -m 'Update' && git push\u000D"
                    }
                }
            ]
        }
    ]
    

    keybindings.json:

    {
      "key": "ctrl+alt+s",
      "command": "extension.multiCommand.execute",
      "args": { "command": "multiCommand.syncAllFiles" },
    }
    

    不需要tasks

    【讨论】:

      【解决方案2】:

      为此,您需要一次运行多个命令,因此您需要一个扩展。使用ryuta46.multi-command 和此配置,Ctrl+Alt+S 将保存并推送您的所有文件

      settings.json (Ctrl+,):

      {
          "multiCommand.commands": [{
              "command":"multiCommand.syncAllFiles",
              "sequence": [
                  "workbench.action.files.saveAll",
                  {
                      "command": "workbench.action.tasks.runTask",
                      "args": "syncAll"
                  },
                  "workbench.action.terminal.toggleTerminal"
              ]
          }]
      }
      

      我添加了一个命令来在命令运行后切换终端,这样每次运行命令时它就不会保持打开状态。不幸的是,即使终端已经打开,它也会发生,所以如果你不希望它这样做,只需删除该行

      keybindings.json (Ctrl+KCtrl+S):

      {
        "key": "ctrl+alt+s",
        "command": "extension.multiCommand.execute",
        "args": { "command": "multiCommand.syncAllFiles" },
      },
      

      tasks.json:

      {
          "tasks": [
              {
                  "label": "syncAll",
                  "type": "shell",
                  "command": "git add .;git commit -m 'Automatic Commit';git pull;git push",
              }
          ]
      }
      

      【讨论】:

      • 谢谢!这是完美的。我所做的唯一修改是:我没有做git pull; git push,而是做了git pull origin master,这正是我所需要的。
      【解决方案3】:

      我认为您可以设置一个任务来为您完成工作https://code.visualstudio.com/docs/editor/tasks

      如果这还不够,请告诉我,我可以给你写一个例子。 任务中最好的事情是,您可以将它们绑定到热键

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-01-21
        • 1970-01-01
        • 2018-02-07
        • 2015-07-27
        • 2016-03-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多