Git - How to change a commit message

Asked

Viewed 252 times

1

I did the following:

Git add . //Adicionei todos os arquivos alterados
Git commit -m 'mensagem que quero editar'

Now, before I push, I want to edit the message from this commit. How do I?

UPDATE

I used the git commit --Amend command, the text editor was opened, applied the changes. To finish the editor and apply the changes, you need to use the :x command

  • 1

    :x is a Vim command, which is an editor that is already installed on linux/Unix and also on Windows git-bash (and many other shells also come with some built-in version). Anyway, it’s an editor that has nothing to do with git, other than the fact that on many systems it’s already set up to be the default editor - although this can be changed in the settings

  • Thanks for the explanation.

  • Just a detail, I do not recommend using --amend after you have already pushed, because when you push you need to give a -f (force), the problem with that is that you lose one of the Tages that may be being worked by another dev, the ideal is to create a new commit and add some identifier that was a replica of change, is much better and safer...

1 answer

4


In case you haven’t pushed :

git commit --amend

But if that’s not the case:

git rebase -i HEAD~Número_de_comites_que_quer_alterar

After doing this a file with the committees will open. You will see a header similar to this:

pick 625d23e Mensagem 0 //Commit 1    
pick f03fd4b Mesagem 1  //Commit 2

Change the word pick for reword. Save and close it. Each committee will be open and you can edit them.

  • If you have pushed, let me know that I will update the answer

  • It would be interesting to leave with the information about push for future research

  • It worked, opened the editor and made the change, but how to finish the editor and apply the change?

  • I was able to save the changes using the command :x Thanks!

  • That’s good. If you find my answer or another satisfactory answer be sure to mark the question as solved

Browser other questions tagged

You are not signed in. Login or sign up in order to post.