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

2

I made 3 commits in the local repository and sent it to the remote repository using push .

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

  • The commit has already been sent to the remote repository;
  • A programmer has updated the local repository with the wrong commit.
  • Another programmer has updated the local repository and then re-committed by updating the remote repository.
  • Another programmer also updated the local repository, made a new commit but did not update the remote repository.
  • That is:

    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 that the commit with the wrong message is B , how to correct the message?

        
    asked by anonymous 04.04.2017 / 16:47

    1 answer

    1

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

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

    But remember: TODO the history after this 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, simply use the

    git revert <commit>
    git push
    

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

        
    04.04.2017 / 17:30