How to rename any commit in git?

Question:

I want to rename a dozen commits, but somehow I can't figure out how to do it. Here, for example, the article is here , but I have a snag after git rebase --interactive , that is, the editor opens the same, but then where and what to write? If I try to write something, then for some reason I write at the very bottom and one character at a time. I did it on windows through the terminal in SourceTree. Maybe there is some other way?

Answer:

git rebase --interactive will show you a kind of plan in a text editor: a list of commits and actions that will be applied to them. By default, all commits are associated with the action pick – save as is. Your first task is to edit the actions to your liking. Available actions are described in a comment separated by # .

#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell

You are primarily interested in the r reword – change the text of the message. I don't know about SourceTree, but the usual shell from the msysgit package (we're talking about Windows, right?) offers the orthodox vim as an editor. If you have the same, and you are not familiar with it, feel free to press the i button on your keyboard and vim will go into edit mode. For the commits you want, replace pick with reword . Now we need to return to command mode by pressing Esc . We save and exit – type on the keyboard :wq , press Enter .

The editor will close and git will start executing your plan. For each commit marked with a reword action, it will open the editor and prompt you to edit the message. Again, if you have vim – press i , edit, Esc , save :wq . Do not pay attention to the comment under the commit text, beaten off by a lattice. It just tells you what to do and will not be included in the text of the message.

Scroll to Top
AllEscort