get rebase --interactive just shows 'noop' and merges all commits
Asked Answered
S

1

6

dev branch is 5 commits ahead of master:

ce30cbd (HEAD -> dev, origin/dev) disabled debugs for libpid
678b1b2 split functionality to libpid and libaccel
6b3f9e2 direct logger test
f5d8841 dev build small changes
2a7c316 Revert "remove Makefile from git"

none of this commits are merge commits etc.

then do next:

git checkout master
git rebase --interactive dev
noop
  
# Rebase ce30cbd..e0bf1e6 onto ce30cbd (1 command)
#
...

I want to select just 3 commits instead of 5 but all of them get merged automatically.
Why it doesn't work and how to handle it?

P.S. I dont want to use cherry-pick as it changes commit hash.

Statistician answered 20/1, 2021 at 20:24 Comment(1)
"I want to select just 3 commits instead of 5 but all of them get merged automatically." Merged with what?Preadamite
P
4

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.

Preadamite answered 20/1, 2021 at 20:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.