0

I wanted to edit a commit message that was already merged into the master branch (which is a protected branch).

To do that, I created a new branch from a master branch and used interactive git rebase(i.e. git rebase -i HEAD~2), rewrite the commit message and pushed the new branch. but when I checked the commits in my branch, it included 6 commits, 2 were same as those listed in editor but the other 4 were all the commits from the last squashed merged request. so the master commit history looks like this:

  • Merge branch aaa into master
  • commit with wrong message (that I wanted to edit) (went into master from branch aaa)
  • Merge branch bbb into master

These 4 commits I see are all the commits in branch bbb that are squashed into one merge commit. Any idea why this happened? Is it because of what is called linearizing the history rather than preserving the merge? but when I selected to go back 2 HEAD, how it included the 3rd commit (Merge branch bbb into master) from master branch

safa
  • 21
  • 4
  • Interactive rebase ignores merge commits unless you tell it not to. Did you? See https://git-scm.com/docs/git-rebase#_rebasing_merges for more. – matt Nov 10 '22 at 02:43
  • 1
    Not an answer to your question, but general advice: unless it's really important to rewrite that commit message, it's best to leave it be. Correctly rewriting it is possible (see the link in matt's comment) but you'll still have to force push the changes, which should not be possible on a protected branch. And you probably won't be able to PR those changes either without creating a new merge that has both the old and rewritten history, unless you're able to force push despite the branch protection. I would talk to your project lead before trying to fix this yourself. – joanis Nov 10 '22 at 02:54
  • To actually answer your question, it would help if we could see your log before and after the operation. I'm guessing matt is right, all you need to do is `git rebase -i --rebase-merges HEAD~2` but it's hard to be sure without seeing your history exactly. When you say that a bbb has been previously squash merged but now you see its four commits, that makes no sense to me, unless your local sandbox was not exactly in synch with origin beforehand. – joanis Nov 10 '22 at 03:01

0 Answers0