Rebasing commits on another branch

I've got problems with moving commits on another branch.
Let's say I have 2 branches, staging and development.
I developed some larger functionality on development branch, and I also worked on other changes on development branch. Now I want to move only the larger functionality to staging branch, but I don't want to move all of the other changes so I cannot merge the whole branch development onto another.
I don't want to also cherry pick selected commits from development onto staging, I'd rather squash them and see only one commit with whole larger functionality on staging branch. As far as I know I should you Rebase dialog from phpStorm, but it's not working as I expected.
If I select branch development and set onto to staging
I'm getting correct Rebase window with commits that I expect
however after finishing the rebasing procedure squached commits are not showing on the staging branch, rather than on development and not only the squashed commits, but also something that looks like merged branch staging into development - which is the other way around!


What is the correct configuration of rebasing commits onto another branch?

Comment actions Permalink

As for the rebasing itself, attempt to rebase development branch onto staging branch (with some commits squashed or not) just inserts all the commits from "staging" that are not yet in "development" branch, and then adds all commits from 'development', possibly squashed or skipped. Thus, if you have had commits s1,s2,s3 in 'staging', not present in 'development', and commits d1, d2, d3, d4 in 'development', then on rebasing development onto staging with d1,d2 and d3 squashed to D1 and d4 skipped, you will get the 'development' branch as
s1,s2,s3,D1. You will stay in 'development' branch, but changed 'development' branch. The 'staging' branch will not get any changes from 'develpment'.

If you want to keep your 'development' branch, but move some commits from it to 'staging' with squashing, you can try the followinh scenario:
- switch to 'development' branch
- create the copy of 'development' branch - i.e. 'dev_copy' and switch to it (for example, select the 'development' head in Log and invoke NewBranch... action)
- invoke rebase in 'dev_copy', specifying the necessary starting point in 'onto' field - for example, like HEAD~3 to rebase last 4 commits
- in the appeared interactive rebase orginize your commits - select what to squash etc
As a result, the 'dev_copy' branch will be modified: it will contain only those commits that you want to put to 'staging'. The original 'development' branch will be kept so that you can continue to work with it.

Now to move the changes from 'dev_copy' to 'staging' branch, you should
- switch to 'staging' branch
- rebase it onto 'dev_copy'.

As a result you will get the 'staging' branch with your changes inserted. At tis point you can delete the 'dev_copy' branch.

Comment actions Permalink

Thank you very much for your answer, it explaines everything. I guess I'm not used to using GIT in phpStorm, and for some actions it doesn't look very user friendly.
For achieving similar results I used to use TortoiseGit, where I could go to merge window, select multiple commits as cherry pick and then the rebase sqush window showed up where I just set up which commits to squash, what commit message should it contain and the squashed commits were rebased onto desired branch.
phpStorm with procedure you described isn't nowhere close to be so simple. Or it might just be wrong methodology of work, and I just should put the larger functionality in separate branch and merge it later...
Anyway, thanks again for explanation :)

Comment actions Permalink

you are right - rebasing support in our products is not very convenient and user-friendly and really needs to be improved.


Please sign in to leave a comment.