0

I have the following commits and I need to update the middle commit with the branch name.

...
...
9a3de7d [#US810469]Add configuration
807fed0 Merge branch 'master' of github.xx.com:org/repo
6153e1e [#US810469] fix typo

I realized when I git rebase -i it doesn't show the merge commits, I learned why here [Merge commits don't appear in git rebase --interactive

In the interactive shell, I saw it says if you remove a line you'll lose the commit. I thought maybe I can add a commit to the place I want :) but that didn't work. It keeps showing me the to-do items to edit. I try to edit them and commit again, but it fails everytime.

How can I change the middle commit's message to "[#US810469]Merge branch 'master' of github.xx.com:org/repo"?

melis
  • 1,145
  • 2
  • 13
  • 30

3 Answers3

2

when you git rebase -i, you are rewriting history in a linear fashion, thus removing your merge commit. You could do this (supposing you are on develop branch)

git branch temp # create temporary branch where you are now (at 6153e1e I suppose)
git reset --hard 807fed0 # move develop branch to the merge commit
git commit --amend # now edit your message to look the way you want it
git cherry-pick temp # since there is only commit in temp branch, cherry-pick will do

if you had multiple commits after your merge commit, then instead of the last cherry-pick you could:

git checkout temp
git rebase develop
git checkout develop
git rebase temp
git branch -d temp

There might be some shortcuts for this, but this way I understand easily the steps; and hopefully you too...

Chris Maes
  • 35,025
  • 12
  • 111
  • 136
0

Rather than inserting a line into the interactive dialog, change the pick to an edit on the commit before you want to insert the commit. Example:

pick 123abccc one
pick 1234abcc two
pick 12345abc three

To insert a new commit before 123abccc (one)

pick 123abccc one
edit 1234abcc two
pick 12345abc three

Before doing a git rebase --continue add any new commits.

EDIT: If you only want to change the commit message change the pick to a reword.

EncryptedWatermelon
  • 4,788
  • 1
  • 12
  • 28
  • 1
    thanks for contributing to StackOverflow. Your answer is correct, but does not seem to be an answer to the question. It seems like she wants to edit the merge commit message which doesn't even show up in the interactive dialog. – Chris Maes Mar 26 '19 at 17:30
0

If what you have after the merge revision you want to modify is only plain old commits (no merges), you could consider doing it by hand:

git checkout 807fed0
git commit --amend -m "Here's the fixed comment"
git cherry-pick 807fed0..master # master or whatever branch
# if everything is ok, then move the local pointer of master (or whatever branch) and push as required
git branch -f master
git push whatever-remote -f master

Ready!

eftshift0
  • 26,375
  • 3
  • 36
  • 60