Is there any way to change a commit message?

7

I work with git on all projects in the company where I work. Unfortunately, some programmers end up putting any message, in a hurry, into commit . This makes things harder, because instead of you seeing the description of what was done in git log , you will have to "kick" by the date of a specific commit .

Some put things like git commit -am ":)" or git commit -am "tudo" .

Example:

commit 18d76fbaa661945ef59f675092f5050d3d7016a3
Merge: 7f0aea2 8ca43f6
Author: XXX XXXX <xxx@email>
Date:   Wed Feb 17 10:26:40 2016 -0200

    all

commit 7f0aea214c26e84b18a8768a7d282b760b7a230a
Author: XXX XXXX <xxx@email>
Date:   Wed Feb 17 10:22:38 2016 -0200

    all

I'd like to know if there's any way to reverse such cliches.

Is there any way to edit a specific commit message?

    
asked by anonymous 18.02.2016 / 12:11

2 answers

6

Complementing the response from Rodrigo , if you just want to change the last commit message, use git commit --amend -m "SUA NOVA MENSAGEM AQUI" .

But if you want to change any other commit, including the first commit of the repository, use git rebase -i --root

In your default terminal text editor (nano, vim, etc) will open a file starting with something similar to this:

pick 4c5877b first commit
pick edbd6ae second commit

4c5877b and edbd6ae are the two commits in my test repository, and first commit and second commit are the commit messages that I used.

Change pick by r or reword to all commits you want to change and save the file. In my case I wanted to modify the second commit , so it looked like this:

pick 4c5877b first commit
reword edbd6ae second commit

The text of the commit (s) you want to change will appear in your text editor, including the message (s) of the commit (s). Change it and save the file (s).

My git log before rebase:

commit edbd6ae914877887c8304895d3a2a1fc4d95769a
Author: xyz <[email protected]>
Date:   Mon Feb 22 20:23:22 2016 -0300

    second commit

commit 4c5877b870d177d5a9dd432ff87a7b006efbc29c
Author: xyz <[email protected]>
Date:   Mon Feb 22 20:23:22 2016 -0300

    first commit

then:

commit e462bfac89165e5af4e0aec60e6758330cbe196d
Author: xyz <[email protected]>
Date:   Mon Feb 22 20:23:22 2016 -0300

    MODIFICADO second commit

commit c3a909e630a806b01d099bf40319cdbc26c96a59
Author: xyz <[email protected]>
Date:   Mon Feb 22 20:23:22 2016 -0300

    first commit
    
23.02.2016 / 00:37
3

You can change the most recent message with the command: git commit --amend

To change older messages, you need to change the base from where you are working so that the most recent one is the one above.

    
18.02.2016 / 12:14