15

I have merged with other branch, and there are few commits after merge, before pushing i want to change the message of the merge. git rebase -i is not displaying the merge commit.

Talespin_Kit
  • 20,830
  • 29
  • 89
  • 135

1 Answers1

28

Not sure if there is a more elegant version, but what you can do is the following:

git checkout <sha of merge>
git commit --amend # edit message
git rebase HEAD previous_branch
knittl
  • 246,190
  • 53
  • 318
  • 364
  • 1
    or a better (more correct) final rebase command: `git rebase previous_branch --onto HEAD` – imz -- Ivan Zakharyaschev Mar 02 '17 at 19:37
  • after this push with force option. Worked. Thanks :) –  Apr 20 '18 at 18:42
  • @imz--IvanZakharyaschev can you explain why and how that is better? – jarno Apr 22 '21 at 08:39
  • 1
    @jarno Nothing, for all practical purposes. `git rebase A B` is equivalent to `git rebase --onto A "$(git merge-base A B)" B`, i.e. it takes all commits not in A, but in B and re-applies them on top of A. In this specific case, this means that the merge commit is included by the commit range, but later ignored by `git rebase` (NB all parents of the merge commit is included in both histories). Specifying "newbase" and "upstream" explicitly is more to type, but does not change the end result here in any way. A quick test in a dummy repo will confirm this. – knittl Apr 22 '21 at 16:00
  • @jarno Yes, @knittl has explained all. In general case, after an amend, if it were not a merge commit which you rewrite, then the simple command would also include the old (rewritten) commit in the range which is to be rebased, and that's not clean to try to apply the old patch on top of the same thing, but amended. So I prefer (for clarity) to always exclude from the `rebase` command the commits that I don't want in the new history and not rely on a smart behavior of `git rebase`. – imz -- Ivan Zakharyaschev Apr 23 '21 at 09:14