When we accept PRs to the main branch they are squashed to a single commit and the original branch is deleted.
I want to know what is the proper flow to start to work on a feature that is based on another while that other feature is waiting for the PR to be accepted.
Let's say the original feature branch is feature-1 and the new one is feature-2. Naively, I created feature-2 from feature-1 then when feature-1 was accepted to the main branch, the history looked like this (note this is just commit order, in term of time, the commits in feature-2 were in parallel to the one in main):
main
* GGG some other commit
* FFF squash commit of feature-1
* EEE some other commit
|
| feature-2
| DDD commit in feature-2
| /
| feature-1
| CCC commit in feature-1
| BBB commit in feature-1
|/
* AAA commit
When feature-1 was accepted to the main branch, and I tried to merge from the main branch, I got many conflicts on the changes made in feature-1 (which existed in feature-2). Rebasing caused even more conflicts.
What is the proper way of work here? Is it to start feature-2 from main and merge/rebase feature-1? Some sort of rebase command from main?
It's ok to do that but you need to be careful not not include the commits of the original
feature-1when rebasing.... so, you need to rebase like this:The problem is that before running the rebase you have something like this:
So, if you run a plain rebase like this
git would have to consider the last common ancestor between both branches, which is
BBBand then start applying all the commits inBBB..feature-2on top ofmain. Because you squashed, git is not aware thatCCCandDDDhave already been applied onmainand so it will try to apply them separately on top ofmain, hence BOOM!!!!.So, you need to do this to come out unscathed:
Then you will get this: