简体   繁体   中英

git Changing a commit message (amend)

I am in a situation where I would like to edit the commit message of an old, already pushed code. In my case I have , of course, my master branch and several other branches, for example v1.0, v2.0 and v3.0. The commit I want to update its messages was made at the time when the branch v1.0 was the 'master'. At each new release of my code I also put a tag on each branch to start and later to follow the different fixes (1.0, 1.1, and so on). For example in branch v1.0, I have a fix (which represents a new version) tagged as 1.1. In my case the code where the commit messages appears is under the tag 1.0. I tried the whole procedure described here https://help.github.com/articles/changing-a-commit-message/ (Amending the message of older or multiple commit messages) but I am still being displayed the commit messages appear "under" the tag 1.0 (I am using SmartGit , that's why I am saying "under"). If I type git show commit_id I still see the commit with the old message...

Does anybody has an idea how to remove this commit message completely from git? Thanks in advance for the replies.

(I am not very good with git, so for now I am just trying to follow the explanations given in internet...)

May be I can recreate the repository and change these commit messages and at the same time keep the rest of the repository's history ? Someone may be did already that ? :)

Changing the commit message or the parent commit changes the commit ID which means as far as git is concerned it is a different commit.

If you want to change tags to point at your modified history you will need to find the corresponding commit in your modified history, point the tag at the new commit and then force push it (see https://stackoverflow.com/a/21127037/5083516 )

But in general changing published history in git is a bad idea and should only be done in extreme circumstances, not merely to correct minor mistakes. Anyone who cloned your repo prior to the history change and then tries to pull is likely to end up in merge hell.

Given no-one has pushed anything upstream since you pushed your commit, you can use:

git push --force-with-lease

after you changed your commit locally via --amend .

This is explained in your link though. I assume you didn't fetch from the repository after pushing the amended commit? The problem may be caused by your tool, try re-importing the whole repository.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM