0

How can I rename my last commit, which I already synchronized with github?

This doesn't work:

git commit --amend -m "New name"

enter image description here

enter image description here

When the command completes displays the new name. But if I synchronize a project with github, then displayed again old wrong name.

enter image description here

Amazing User
  • 3,473
  • 10
  • 36
  • 75
  • 1
    You'll need to explain what you mean by "doesn't work", and probably also what you mean by "rename a commit" (commits don't have anything called a "name", just author+committer+tree+parents+log message). – torek Feb 21 '15 at 20:06
  • @torek The question is indeed very unclear; I'm guessing that, by "doesn't work", the OP means that he can't push his amended commit. – jub0bs Feb 21 '15 at 20:09
  • @torek I've execute command from my question and nothing happens. Name does not changed. Under the name I understand that highlighted in red in the screenshot – Amazing User Feb 21 '15 at 20:10

1 Answers1

1

Rewording a commit message is equivalent to changing the commit itself from a branch history point of view. In both cases you are changing the hash of the commit. Since you have already pushed that branch to GitHub, your next push will fail unless you force

git push origin master -f

Your modification won't appear on the remote until you do that. You can, however, see that it's been correctly modified locally using git log or visually with gitk --all

Sébastien Dawans
  • 4,537
  • 1
  • 20
  • 29
  • *Rewording a commit message is equivalent to changing the commit itself.* [Not exactly](http://stackoverflow.com/questions/26050327/how-does-git-commit-amend-work-exactly/26050416#26050416). – jub0bs Feb 21 '15 at 20:17
  • From a branch history point of view it is -- both have the effect of changing the HASH of the commit. That's what I meant, I'll edit. – Sébastien Dawans Feb 21 '15 at 20:17
  • Should I first execute your command and then mine? If yes, then unfortunately it still doesn't works – Amazing User Feb 21 '15 at 20:25