I had a branch which was merged off of commit A of branch main. I made a few changes and ended up like this:
A-B-C-D
I then merged the branch back to main introducing a merge commit. A fast-forward merge would have sufficed but our policy is to create a merge commit. I noticed a spelling mistake in the merge's commit message and did a git commit --amend to correct it. The history now looks like this. Where E is the merge commit.
A-B-C-D-E
Parents of E are displayed by git log as Merge: A D.
The problem now is that main does no longer contain the changes of commits B, C or D.
- For example C changed file
foo/barbut when opening the file as ofEthe file is in state `A´. - Also a
git log -- foo/bardoes not list commit C. - Executing
git diff A Eshows an empty diff as doesgit show E.
This is the corresponding section from my reflog:
E HEAD@{93}: commit (amend): Finish Hotfix
Z HEAD@{94}: commit (merge): Finsh Hotfix
A HEAD@{95}: checkout: moving from hotfix to main
D HEAD@{96}: commit: Changes
C HEAD@{97}: commit: Changes
B HEAD@{98}: commit: Changes
A HEAD@{99}: checkout: moving from main to hotfix
When I try to merge the changes again (git merge D) git states Already up to date..
- How did I end up like this? Caused amending the problem?
- What is my best option to fix this issue without cluttering the history too much? The branches have been pushed already a few days ago and cannot be rewritten anymore.