How to change the message from a commit sent to the remote repository

Asked

Viewed 842 times

2

I did 3 commits in the local repository and uploaded them to the remote repository using push.

I noticed that one of the commits message was wrong. How do I change the message in the following conditions:

  1. Commit has already been uploaded to the remote repository;
  2. A programmer updated the local repository with the wrong commit.
  3. Another programmer updated the local repository and then made a new commit by updating the remote repository.
  4. Another programmer also updated the local repository, made a new commit but did not update the remote repository.

That is to say:

1. Repositóro remoto 
       o--->A--->B--->C

2. Programador X
       o--->A--->B--->C

3. Programador Y
       o--->A--->B--->C--->D
   Repositóro remoto 
       o--->A--->B--->C--->D

4. Programador Z
       o--->A--->B--->C--->E
   Repositóro remoto 
       o--->A--->B--->C--->D

Assuming the commit with the wrong message is the B, how to fix the message?

  • There’s no way you can fix it, the only alternative would be if no one had done the pull, you could fix it locally and make a push force, which is not cool because it totally changes the history of the repository and other users would have problems

  • @Gerep So what is recommended to do? A commit with a wrong message can also be problematic.

  • You can try using the command git revert: https://git-scm.com/docs/git-revert =(

1 answer

1

As it was put in the comments, the drastic solution would be for you to reset to the immediately previous commit with the command:

git reset --hard <commit>
git push --force

But remember: ALL OVER the history after that commit will be lost forever.

If you want, you can also do the revert command, which eliminates the commit without undoing the history. To do this, just use the command

git revert <commit>
git push

But this command will lose the content of your commit, but will not affect the history after it.

  • 1

    But if revert eliminates the commit content, what about the changes that were made to that commit? Do I have to redo them? There’s no way in Git to insert a note, for example, leaving the original message, but with a correction note, or something like that?

  • 1

    As has been said in the other comments. There’s no way you can just change the commit message or change the content of a single commit file or even the commit time. These operations are atomic. You could redo the change that was in this commit in another, with the right message.

Browser other questions tagged

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