Have a git repo with this history (initial repo):
A-B---C---D-H-I
\ /
E-F-G
Want to change history to:
I`(will squash all from B till I)
/
A-B
\
E-F-G
But when I tried rebase -i <SHA "A"> from G, D is absent from the list of commits available, I see:
pick B
pick C
pick E
pick F
pick G
pick H
pick I
If I remove commits from the of shoot branch E-F-G and save order to rebase as:
pick B
squash C
squash H
squash I
again I lost changes from commit "D"
I decided problem by git reset --soft <SHA "A"> and after commit
But I wonder why git did this?
And did exist the simple method to remove from the initial repo not demanded part of merged branch "E-F-G" without rebase and create additional commits (by idea the commit "C" & "D" are summarized the all changes after "A")?
>Solution :
D is a merge commit so there are no changes in it so there is nothing to keep from it (unless there were merge conflict resolution captured). If you want to confirm do git show <D hash> and it should show you that nothing is changing (or the conflict resolutions).
Because you are rebasing this commit is no longer going to have any reason to exist so it disappears.
The next time you do this operation I would strongly suggest you do the following, which I do whenever I’m rebasing or squashing…. Note that this assumes and is only true for when you are only rebasing to squash commits or reorder history and not if you are editing/ammending anything
git diff <resulting branch> <original_branch|original_hash|origin/my_original_branch> This way we can see that nothing changes except commit history/commit messages, that no content changed.