Rename a merged commit without losing that commit's parents

416 views Asked by At

TL;DR: Is it possible to rename a commit from a merged (no fast forward merge) branch - without destroying history?

I want to rename a commit. Something like rebase --interactive HEAD~5. But I want to keep the HEADs in their current position. Rebase will flatten the log.

I'm using feature branches

*   c3cb3ad - Merge branch 'featureX' into develop (15 minutes ago) <FOO>
|\  
| * d945c71 - Did stuff (17 minutes ago) <FOO>
| * d4356f4 - inline commits are aweosm <FOO> (27 minutes ago) <LSC>
|/  
*   6ef9569 - bla bla bla

This is how I git:

~/dev/foo/ (develop)$ git checkout -b featureX
~/dev/foo/ (featureX)$ git add foo.html
~/dev/foo/ (featureX)$ git commit -m "inline commits are aweosm"
~/dev/foo/ (featureX)$ git checkout develop
~/dev/foo/ (develop)$ git merge --no-ff featureX
~/dev/foo/ (develop)$ git branch -D featureX
~/dev/foo/ (develop)$ git add bar.html
~/dev/foo/ (develop)$ git commit -m "Lorem Ipsum"

... oh crap. There's a typo in my commit message!

1

There are 1 answers

1
Ôrel On BEST ANSWER

Use git rebase with --preserve-merges