Your rebase is a no-op because you've asked to rebase master on top of dev, but master is behind dev so there's nothing to rebase.
For a technical explanation, look at Rebase ce30cbd..e0bf1e6 onto ce30cbd
. ce30cbd..e0bf1e6
means "commits which are accessible from e0bf1e6 (master) except those accessible from ce30cbd (dev)". Since all of master's commits are accessible from dev, there are no commits.
See Revision Selection in Pro Git and gitrevisions for more.
I want to select just 3 commits instead of 5 but all of them get merged automatically.
Rebase will not merge, that has to be done as a separate step.
It's unclear what you want to do with those selected commits, but I'll assume you want to select 3 commits out of dev and put them on master.
If you want to throw out the other two commits...
git checkout dev
git rebase -i master
Then delete the unwanted commits in the editor. dev will be rewritten to be just those three commits.
If you want to keep the existing dev commits, first make a new branch, then rebase.
git checkout -b new-dev
git rebase -i master
dev will be unchanged, new-dev will contain only the selected commits.
Once that's done, merge the branch into master.
git checkout master
git merge dev
This won't do a merge. Because dev is a simple ancestor of master (ie. there have been no more commits on master) it will simply "fast-foward"; master will jump to the same commit as dev. If you want to force a merge, use git merge --no-ff
. This is often useful to preserve a set of commits as having been done as a group in a branch.
P.S. I dont want to use cherry-pick as it changes commit hash.
Rebase will also change the commit hash. Rebase is basically a series of cherry picks.
The commit hash is a checksum of the commit's contents and all its parents. This is fundamental to how Git works. Any time you "rewrite" a commit (commits are not rewritten, new commits are made) its commit hash, and the hashes of all its descendants, must change.
So you can simply cherry pick the three commits onto master.
git co master
git cherry-pick commita commitb commitc
See Rewriting history in Pro Git for more.