This is my current git. And now when i try to change commit messages in the past (before the git merge), i think it's impossible because of this merge request in the middle.
How do I straighten this without losing the granular commits in the history?
I have googled and found answers about git merge squashing but they sound scary and without visuals, I dare not experiment for fear of losing my history.
There is undoubtedly some cleaner way to do this, but the basic idea is that you want to work with the commits just before the merge and rebase appropriately. But the commits after the merge-point are a bit of a pain. If there are no merge conflicts, this can be fairly painless. If there are any merge conflicts, you will probably have to resolve each manually and it may be frustrating. For example:
Disclaimer: although commits are immutable and it is genuinely difficult to actually lose any data with git,
git reset --hard
does modify the working directory. If there are changes in the working directory that are not committed,git reset --hard
will cause those changes to be lost. Consider yourself warned. In short, if you blindly follow the above commands without making an effort to understand what they are doing, it is your own fault if you cause yourself trouble.Also note that I'm cherry-picking all of the commits rather than rebasing, but the principal is the same.