I have a branch with some regular commits and one merge-commit from the develop
branch. There were conflicts that were successfully resolved during the merge.
* 18b0bd7 (HEAD -> my_branch, origin/my_branch) My commit №6
* b7c7d02 My commit №5
* bd4b580 My commit №4
* c902168 Merge remote-tracking branch 'develop' into my_branch // THERE'RE SOME SUCCESSFULLY RESOLVED CONFLICTS!
|\
| * 3428461 Commit №3 from develop
| * e40fc07 Commit №2 from develop
| * 48697c2 Commit №1 from develop
* | dac8571 My c0mdiT №3
* | 1cf1712 My commit №2
* | 6aa6a86 My commit №1
I want to edit message of dac8571
. In cases like that I usually set the branch head at it, use git commit --ammend ...
and then git rebase ...
to move upstream commits onto the edited one. But the problems start when I try to edit a commit before merge-commit with resolved conflicts. Git forces me to resolve them again, but that's not an option for me because they're already resolved in my_branch
. All I have to do is change the commit description of the commit in the middle of my_branch
and resolve the merge conflicts in the same way they are already resolved. I don't need to make changes to the code of those commits.
How can I achieve it? I spent a lot of time trying to use cherry-pick
, rebase --merge-merges
, rerere
, but I didn't get it to work properly. Some of these things are too complicated for me, and others I most likely use incorrectly. Could you, please, explain to me clearly how to change the commit message before the merge commit?
CodePudding user response:
It can be done with some work
git checkout dac8571
git commit --amend
# let's create a new revision for c902168 using HEAD as the first parent
git commit-tree -p HEAD -p 3428461 -m "some comment" c902168^{tree}
# previous command will output a revision ID
git rebase --onto the-revision-id-from-commit-tree c902168 my-branch
And that's it
CodePudding user response:
git replace --edit dac8571
git filter-branch
and for the log you've shown here that'll do it. If the history's really long git filter-branch -- dac8571^! @
to stop looking for stuff that needs fixing at its parents (there's only one here, ^! gets them all however many there are).