Pular para conteúdo

GIT_COMMIT - Criar Commit com Mudanças

O que é este Node?

O GIT_COMMIT é o node responsável por criar um commit com as mudanças que estão na staging area do Git. Ele executa o comando git commit -m "mensagem".

Por que este Node existe?

Após adicionar arquivos à staging area, precisamos criar um commit para registrar essas mudanças no histórico do Git. O GIT_COMMIT existe para:

  1. Versionamento: Registrar mudanças no histórico do repositório
  2. Documentação: Criar ponto de referência com mensagem descritiva
  3. Rastreabilidade: Permitir rollback e comparação de versões
  4. Colaboração: Compartilhar mudanças específicas com a equipe

Como funciona internamente?

Quando o GIT_COMMIT é executado, o sistema:

  1. Recebe mensagem: Obtém a mensagem do commit
  2. Substitui variáveis: Aplica variáveis do contexto na mensagem
  3. Executa commit: Roda git commit -m "mensagem"
  4. Captura output: Obtém detalhes do commit criado
  5. Se erro: Lança exceção (sem mudanças, mensagem vazia, etc)
  6. Se sucesso: Retorna confirmação do commit

Código interno (git.executor.ts:124-128):

private async commit(repoPath: string, message: string, context: ExecutionContext): Promise<any> {
  const replacedMessage = this.replaceVariables(message, context.variables);
  const output = await this.execGit(repoPath, `commit -m "${replacedMessage}"`, context);
  return { output, committed: true };
}

Quando você DEVE usar este Node?

Use GIT_COMMIT sempre que precisar de criar um commit com mudanças:

Casos de uso

  1. Backup automatizado: "Criar commit diário com mudanças de configuração"
  2. Geração de código: "Commit de código gerado automaticamente"
  3. Documentação: "Commit automático de docs atualizadas"
  4. Sincronização: "Commit de mudanças antes de deploy"

Quando NÃO usar GIT_COMMIT

  • Sem mudanças na staging area: Use GIT_ADD primeiro
  • Mensagem não descritiva: Use mensagens claras e objetivas
  • Mudanças não relacionadas: Separe em múltiplos commits

Parâmetros Detalhados

repositoryPath (string, obrigatório)

O que é: Caminho absoluto para o repositório Git onde o commit será criado.

Padrão: Nenhum (obrigatório informar)

Flow completo para testar:

{
  "name": "Teste Git Commit - Repository Path",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Path",
        "parameters": {
          "variable": "repo_path",
          "value": "/var/www/projeto"
        }
      }
    },
    {
      "id": "git_commit_1",
      "type": "git",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Commit",
        "operation": "commit",
        "repositoryPath": "{{repo_path}}",
        "message": "test: automated commit",
        "responseVariable": "commit_result"
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Confirmar",
        "parameters": {
          "message": "Commit criado!\n{{commit_result.output}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 900, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "variable_1" },
    { "source": "variable_1", "target": "git_commit_1" },
    { "source": "git_commit_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Teste: Execute o flow. Sistema criará commit no repositório especificado.

message (string, obrigatório)

O que é: Mensagem descritiva do commit que explica as mudanças realizadas.

Padrão: Nenhum (obrigatório informar)

Boas práticas de mensagem: - Use prefixos: feat:, fix:, docs:, refactor: - Seja conciso mas descritivo - Use imperativo: "add" não "added" - Máximo 50 caracteres no título

Flow completo para testar:

{
  "name": "Teste Git Commit - Message",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "input_1",
      "type": "input",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Mensagem",
        "parameters": {
          "message": "Digite a mensagem do commit:",
          "variable": "commit_msg"
        }
      }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Timestamp",
        "parameters": {
          "variable": "timestamp",
          "value": "{{date}}"
        }
      }
    },
    {
      "id": "git_commit_1",
      "type": "git",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Commit com Timestamp",
        "operation": "commit",
        "repositoryPath": "/var/www/app",
        "message": "{{commit_msg}} - {{timestamp}}",
        "responseVariable": "commit_result"
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Resultado",
        "parameters": {
          "message": "Commit criado: {{commit_msg}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "input_1" },
    { "source": "input_1", "target": "variable_1" },
    { "source": "variable_1", "target": "git_commit_1" },
    { "source": "git_commit_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Teste: Digite "feat: add new feature" quando solicitado. Sistema criará commit com mensagem e timestamp.

responseVariable (string, opcional)

O que é: Nome da variável onde o resultado do commit será armazenado.

Padrão: Nenhum (resultado não é armazenado)

Estrutura do retorno:

{
  "output": "[main abc1234] feat: add new feature\n 2 files changed, 15 insertions(+), 3 deletions(-)",
  "committed": true
}

Flow completo para testar:

{
  "name": "Teste Git Commit - Response Variable",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "git_commit_1",
      "type": "git",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Commit com Variável",
        "operation": "commit",
        "repositoryPath": "/var/www/app",
        "message": "chore: automated backup",
        "responseVariable": "commit_info"
      }
    },
    {
      "id": "condition_1",
      "type": "condition",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Verificar Commit",
        "parameters": {
          "condition": "{{commit_info.committed}} === true"
        }
      }
    },
    {
      "id": "message_success",
      "type": "message",
      "position": { "x": 700, "y": 50 },
      "data": {
        "label": "Sucesso",
        "parameters": {
          "message": "Commit criado com sucesso!\n{{commit_info.output}}"
        }
      }
    },
    {
      "id": "message_error",
      "type": "message",
      "position": { "x": 700, "y": 150 },
      "data": {
        "label": "Erro",
        "parameters": {
          "message": "Falha ao criar commit"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 900, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "git_commit_1" },
    { "source": "git_commit_1", "target": "condition_1" },
    { "source": "condition_1", "target": "message_success", "label": "true" },
    { "source": "condition_1", "target": "message_error", "label": "false" },
    { "source": "message_success", "target": "end_1" },
    { "source": "message_error", "target": "end_1" }
  ]
}

Teste: Execute o flow. Sistema verifica se commit foi bem-sucedido.

Parâmetros

Campo Tipo Obrigatório Descrição
operation string Sim Deve ser "commit"
repositoryPath string Sim Caminho do repositório local
message string Sim Mensagem descritiva do commit
responseVariable string Não Variável para armazenar resultado

Exemplo 1: Commit Automatizado de Configurações

Objetivo: Criar commit diário de arquivos de configuração

JSON para Importar

{
  "name": "Backup Diário de Configs",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Data Atual",
        "parameters": {
          "variable": "current_date",
          "value": "{{date}}"
        }
      }
    },
    {
      "id": "git_add_1",
      "type": "git",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Add Configs",
        "operation": "add",
        "repositoryPath": "/etc/app-configs",
        "pathsToAdd": "*.conf",
        "responseVariable": "add_result"
      }
    },
    {
      "id": "git_commit_1",
      "type": "git",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Commit Backup",
        "operation": "commit",
        "repositoryPath": "/etc/app-configs",
        "message": "chore: daily config backup - {{current_date}}",
        "responseVariable": "commit_result"
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Confirmação",
        "parameters": {
          "message": "Backup de configurações realizado!\nData: {{current_date}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1100, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "variable_1" },
    { "source": "variable_1", "target": "git_add_1" },
    { "source": "git_add_1", "target": "git_commit_1" },
    { "source": "git_commit_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Saída esperada:

Sistema: Backup de configurações realizado!
Data: 2025-10-13

Exemplo 2: Commit com Conventional Commits

Objetivo: Criar commits seguindo padrão Conventional Commits

JSON para Importar

{
  "name": "Conventional Commit",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "input_1",
      "type": "input",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Tipo",
        "parameters": {
          "message": "Tipo (feat/fix/docs/refactor):",
          "variable": "commit_type"
        }
      }
    },
    {
      "id": "input_2",
      "type": "input",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Escopo",
        "parameters": {
          "message": "Escopo (auth/api/ui):",
          "variable": "commit_scope"
        }
      }
    },
    {
      "id": "input_3",
      "type": "input",
      "position": { "x": 700, "y": 100 },
      "data": {
        "label": "Descrição",
        "parameters": {
          "message": "Descrição curta:",
          "variable": "commit_desc"
        }
      }
    },
    {
      "id": "variable_1",
      "type": "variable",
      "position": { "x": 900, "y": 100 },
      "data": {
        "label": "Montar Mensagem",
        "parameters": {
          "variable": "full_message",
          "value": "{{commit_type}}({{commit_scope}}): {{commit_desc}}"
        }
      }
    },
    {
      "id": "git_commit_1",
      "type": "git",
      "position": { "x": 1100, "y": 100 },
      "data": {
        "label": "Commit",
        "operation": "commit",
        "repositoryPath": "/var/www/app",
        "message": "{{full_message}}",
        "responseVariable": "commit_result"
      }
    },
    {
      "id": "message_1",
      "type": "message",
      "position": { "x": 1300, "y": 100 },
      "data": {
        "label": "Sucesso",
        "parameters": {
          "message": "Commit criado: {{full_message}}"
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1500, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "input_1" },
    { "source": "input_1", "target": "input_2" },
    { "source": "input_2", "target": "input_3" },
    { "source": "input_3", "target": "variable_1" },
    { "source": "variable_1", "target": "git_commit_1" },
    { "source": "git_commit_1", "target": "message_1" },
    { "source": "message_1", "target": "end_1" }
  ]
}

Saída esperada:

Usuário: feat
Usuário: auth
Usuário: add OAuth2 support
Sistema: Commit criado: feat(auth): add OAuth2 support

Exemplo 3: Commit com Validação de Mudanças

Objetivo: Verificar se há mudanças antes de criar commit

JSON para Importar

{
  "name": "Commit com Validação",
  "nodes": [
    {
      "id": "start_1",
      "type": "start",
      "position": { "x": 100, "y": 100 },
      "data": { "label": "Início" }
    },
    {
      "id": "git_status_1",
      "type": "git",
      "position": { "x": 300, "y": 100 },
      "data": {
        "label": "Verificar Status",
        "operation": "status",
        "repositoryPath": "/var/www/docs",
        "responseVariable": "status_result"
      }
    },
    {
      "id": "condition_1",
      "type": "condition",
      "position": { "x": 500, "y": 100 },
      "data": {
        "label": "Tem Mudanças?",
        "parameters": {
          "condition": "!{{status_result.status}}.includes('nothing to commit')"
        }
      }
    },
    {
      "id": "git_add_1",
      "type": "git",
      "position": { "x": 700, "y": 50 },
      "data": {
        "label": "Add All",
        "operation": "add",
        "repositoryPath": "/var/www/docs",
        "pathsToAdd": ".",
        "responseVariable": "add_result"
      }
    },
    {
      "id": "git_commit_1",
      "type": "git",
      "position": { "x": 900, "y": 50 },
      "data": {
        "label": "Commit",
        "operation": "commit",
        "repositoryPath": "/var/www/docs",
        "message": "docs: automated documentation update",
        "responseVariable": "commit_result"
      }
    },
    {
      "id": "message_committed",
      "type": "message",
      "position": { "x": 1100, "y": 50 },
      "data": {
        "label": "Sucesso",
        "parameters": {
          "message": "Documentação commitada com sucesso!"
        }
      }
    },
    {
      "id": "message_no_changes",
      "type": "message",
      "position": { "x": 700, "y": 150 },
      "data": {
        "label": "Sem Mudanças",
        "parameters": {
          "message": "Não há mudanças para commitar."
        }
      }
    },
    {
      "id": "end_1",
      "type": "end",
      "position": { "x": 1300, "y": 100 },
      "data": { "label": "Fim" }
    }
  ],
  "edges": [
    { "source": "start_1", "target": "git_status_1" },
    { "source": "git_status_1", "target": "condition_1" },
    { "source": "condition_1", "target": "git_add_1", "label": "true" },
    { "source": "condition_1", "target": "message_no_changes", "label": "false" },
    { "source": "git_add_1", "target": "git_commit_1" },
    { "source": "git_commit_1", "target": "message_committed" },
    { "source": "message_committed", "target": "end_1" },
    { "source": "message_no_changes", "target": "end_1" }
  ]
}

Saída esperada (com mudanças):

Sistema: Documentação commitada com sucesso!

Saída esperada (sem mudanças):

Sistema: Não há mudanças para commitar.

Resposta do Node

{
  "output": "[main abc1234] feat: add new feature\n 2 files changed, 15 insertions(+), 3 deletions(-)",
  "committed": true
}

Boas Práticas

SIM:

  • Use mensagens descritivas e claras
  • Siga padrão Conventional Commits
  • Use prefixos: feat, fix, docs, refactor, test
  • Commite mudanças relacionadas juntas
  • Verifique status antes de commit
  • Use imperativo na mensagem

NÃO:

  • Não use mensagens genéricas como "update" ou "fix"
  • Não commite arquivos não relacionados juntos
  • Não commite código com erros
  • Não use mensagens muito longas
  • Não commite arquivos sensíveis (senhas, tokens)
  • Não esqueça de adicionar arquivos à staging area

Dicas

💡 Dica 1: Use GIT_ADD antes do commit para adicionar arquivos

💡 Dica 2: Verifique com GIT_STATUS se há mudanças antes de commitar

💡 Dica 3: Use variáveis para incluir timestamp ou informações dinâmicas

💡 Dica 4: Siga padrão de mensagens da equipe (Conventional Commits é recomendado)

💡 Dica 5: Após commit, use GIT_PUSH para enviar ao remoto

Próximo Node

GIT_ADD - Adicionar arquivos antes de commit → GIT_PUSH - Enviar commit ao repositório remoto → GIT_STATUS - Verificar status antes de commit