> For the complete documentation index, see [llms.txt](https://cumbucadev.gitbook.io/github-essentials/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cumbucadev.gitbook.io/github-essentials/dia-4/desfazendo-alteracoes-localmente/alterando-o-ultimo-commit-via-git-commit-amend.md).

# Alterando o Último Commit via \`git commit --amend\`

O Git oferece diversas formas de modificar o último commit **local**, permitindo ajustes rápidos quando algo não sai como esperado. Vamos focar nas opções mais simples e úteis para iniciantes:&#x20;

* Corrigir a mensagem do commit
* Adicionar arquivos esquecidos
* Modificar o último commit, adicionando arquivos e mudando a mensagem

## **Modificar a Mensagem do Último Commit**

Se você deseja apenas alterar a mensagem do último commit, utilize:

> <mark style="color:purple;">git</mark> <mark style="color:orange;">commit</mark> <mark style="color:blue;">--amend -m "Nova mensagem do commit"</mark>

Isso irá modificar a mensagem do commit sem alterar seu conteúdo.

## **Adicionar Arquivos ao Último Commit**

Se você esqueceu de adicionar um arquivo antes do commit, utilize o comando <mark style="color:purple;">git</mark> <mark style="color:orange;">commit</mark> <mark style="color:blue;">--amend --no-edit</mark> após adicionar o arquivo:

> <mark style="color:purple;">git</mark> <mark style="color:orange;">add</mark> <mark style="color:green;">arquivo\_esquecido.txt</mark>
>
> <mark style="color:purple;">git</mark> <mark style="color:orange;">commit</mark> <mark style="color:blue;">--amend --no-edit</mark>

Isso adiciona o arquivo ao commit sem modificar a mensagem.

## **Modificar o Último Commit, Adicionando Arquivos e Mudando a Mensagem**

Se você precisa adicionar um arquivo e também alterar a mensagem do último commit, use:

> <mark style="color:purple;">git</mark> <mark style="color:orange;">add</mark> <mark style="color:green;">arquivo\_esquecido.txt</mark>
>
> <mark style="color:purple;">git</mark> <mark style="color:orange;">commit</mark> <mark style="color:blue;">--amend -m "Nova mensagem com arquivos adicionados"</mark>

Isso faz as duas coisas: adiciona o arquivo e altera a mensagem do commit.

{% hint style="warning" %}
Esta é uma explicação simplificada para fins didáticos. Para explorar todas as possibilidades da opção <mark style="color:blue;">`--amend`</mark> do comando <mark style="color:purple;">`git`</mark><mark style="color:orange;">`commit`</mark>, consulte a [documentação oficial](https://git-scm.com/docs/git-commit/pt_BR).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://cumbucadev.gitbook.io/github-essentials/dia-4/desfazendo-alteracoes-localmente/alterando-o-ultimo-commit-via-git-commit-amend.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
