Is there any way to change a commit message?

Asked

Viewed 998 times

7

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

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 wonder if there is any way to reverse such lambanças.

Is there any way to edit a specific commit message?

  • What can I do to improve my question? The negative vote is in this sense?

  • 4

    There is an easier way, upgrade programmers or replace them with newer versions where this bug has already been fixed :D

2 answers

7


Complementing the response of 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 repository’s first commit, use git rebase -i --root

In your standard 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 existing commits in my test repository, and first commit and second commit are the commit messages I used.

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

pick 4c5877b first commit
reword edbd6ae second commit

The information from the commit(s) you wanted to change will appear in your text editor, including the same(s) message(s). Change it(s) and save the file(s) (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

and 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
  • That’s just what I needed, thanks :)

3

You can change the latest 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 latest one is the top.

Browser other questions tagged

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