0

I created a branch from master and submitted 2 commits on the branch.

Now I need to merge the branch back into master, somehow the master has changed, I will merge more commits into master than just my 2 commits.

What's the best solution here? Can I just move the branch ( with 2 commits) into the new master? I mean, if I want merge into master, I should only submit the 2 commits. And I hope what I do will not affects others who working on the same repository.

I tried git rebase, but it messes with many commits than just these 2.

0

2 Answers 2

1

If you don't intend to fully merge your branch to master, but need those two commits on master, you can try a cherry-pick.

See "How to cherry pick a range of commits and merge into another branch" and the git cherry-pick man page.

You have other options (even using git merge) detailed in "Is it possible to exclude specific commits when doing a git merge?"

0
x----x-----x---x---master
      \
       `--x---x--your branch

If that is your state, then these are your options:

  1. Cherry pick the commits from your branch onto master
  2. Rebase your branch onto master and then merge master in
  3. Merge your branch into master.

Regardless of what you do, once you have pushed your changes, others pulling from the same repository you pushed to will get all the commits necessary.

When you tried to rebase, that's not Git "messing with many commits". What you probably encountered were conflicts that needed to be addressed. Git would only be creating two new commits, at the tip of master, not many.

If you're not comfortable with rebase, I would suggest merging your branch into master. It is the safest operation as it does not involve a recalculation of commits. You will still get conflicts, but you will have to solve them no matter which route you take.

Not the answer you're looking for? Browse other questions tagged or ask your own question.