Reputation: 2917
the commit I would like to change its message is already pushed and it is in the middle of 5 commits. Is there any way to edit the commit message? What happend after editing, when somebody has already pulled the commit?
Upvotes: 3
Views: 9791
Reputation: 36700
As this is tagged with tortoisegit, I will show you how you could achieve this in TortoiseGit
Update: updated this answer to start from the log. It isn't easier, but it's better and will not result in conflicts
Upvotes: 5
Reputation: 14429
It is generally not advisable to alter commits that are already publicly availabe. As you realized yourself, editing such a commit when someone else is already working on top of it may lead to conflicts when the other person tries to publish their work.
Having said that, git rebase -i HEAD~5
will allow you to interactively rebase your last five commits. It will open a ToDo file in your editor that allows yout to rewrite your history as needed. Among others, there will be a reword
option, allowing you to change the commit message for a particular commit. You just have to change the pick
in front of said commit to reword
and save the file, and git will promt you for the new commit message.
Be aware, hoever, that you will create an entirely new commit, and if you want to publish it, you will have to push with the --force
option.
Upvotes: 2
Reputation: 39951
It's considered best practice to not alter what has already been pushed.
However, you can edit any commit with git rebase -i
and choose r (reword)
for the commit you'd like to change.
You need to push it with push -f
(forced push) if you've pushed it before.
You will alter the entire tree from that commit and forward so all other that have cloned the repository will need to do a git pull
to get it right. If they have changes based on the current tree you will make it hard for them so best thing is to make everyone push their changes, "freeze" the repository and then have them pull again after your push.
Upvotes: 1