首页 > 解决方案 > Rebase-merge another branch into the current one

问题描述

Is there an easy way to rebase another branch onto the current one without moving the other branch or switching to it? This is the feature that github calls "rebase and merge" in pull requests.

So I want to have the same result as if running these commands (starting on master):

git checkout -b tmp feature
git rebase master
git checkout master
git merge --ff-only tmp
git branch -d tmp

But it is important to me that I don't actually switch to the other branch. feature might be many commits behind master and I am working on a huge c++ codebase. I don't want a full rebuild to merge a branch that only touched two files.

I tried git cherry-pick HEAD^ feature, but that complains if commits from feature where cherry-picked to master before. Also, I would prefer to have the option of an interactive rebase, so I can change a commit message or leave out a commit in this step.

I also found git merge feature --strategy=ours && git rebase HEAD^. But creating that useless merge seems strange and if I abort the rebase, I now have to remember to delete the merge from my master.

In case I am missing something very basic and should approach this completely differently: My context is that I'm using git-svn to work against a svn repository. I have a worktree with a current build of trunk. I want to get my feature-branch commits, make sure the new state builds, maybe polish some commits and push the changes to the svn repo.

标签: git

解决方案


推荐阅读