简体   繁体   中英

Commit message amend using rebasing on feature branch and then merging into master

I have an old commit which was made on one old branch, say "old_branch_1". This commit was merged into my "master" branch via a Pull Request. Now I need to amend the message of that commit. So I followed steps as below:

  1. Created a new branch from "master", say "new_branch_1".
  2. Did checkout new_branch_1.
  3. used git rebase -i HEAD~50 And then amended the required commit message.
  4. Once, rebase was completed. I was a 100 commits ahead of remote and around 120 commits behind of remote.
  5. Did git pull (and resolved the conflicts). Now I was 200 odd commits ahead.
  6. Did git push.
  7. Now, I have raised a PR to my master branch.

What I am not sure about is, whether post merging of PR, will it replace the old commit with new message or will it add this new commit to the top of master branch history.

I really need to get rid of old commit message from the history. since the old message is causing issues when merging my code into production branches.

TL;DR: The only way to get rid of the comment is to rebase and then force push. That will most likely cause a lot of headaches if you're part of a team that has various topic branches currently in development.

A rebase changes the commit IDs of every affected commit. After your rebase, you had the same number of commits as master at the time you branched off of it, but the most recent 50 had different commit ids. At that point you should have been 50 commits ahead and 50 behind master . Not sure how you wound up being 100 commits ahead. The additional "commits behind" could have occurred if other code had been merged into master between your checkout and the completion of your rebase.

When you merged master back into your branch, you brought back all 50 of those commits your rebase modified, including the commit messages. Your PR will not overwrite anything in the existing remote, but only add 50 more commits that are identical to the corresponding commits in your remote, with the exception that one of your new commits has a different comment message.

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