将一些提交移到另一个分支 [英] Move some commits to another branch

查看:78
本文介绍了将一些提交移到另一个分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只有一个分支有git repo

I have git repo in only one branch

A-B-C-D-E (master)

我想将提交B,C和D拆分到另一个名为developer的分支

I want to split commits B, C and D to another branch called develop

A-E (master)
 \
  B-C-D (develop)

最简单的方法是什么?无需关心远程回购. cherry-pick只是将提交复制到另一个分支吗?我认为rebase是必需的,但是我以前没有用过,所以我想在第一次尝试时就拥有这个权利:)

What is the easiest way to do this? No need to care about remote repo. Does cherry-pick just copy a commit to another branch? I think rebase is needed but I haven't used it before and I'd like to have this right on first try :)

有一些相关的问题,但是这些没有最后一次提交E要处理.

There are some related questions but these do not have the last commit E to be taken care of.

  • How to move commits to another branch?
  • git: how to move some commits to new branch
  • How to move certain commits to another branch in git?

推荐答案

这2条命令应该可以解决问题:

This 2 commands should do the trick:

git branch develop D #create develop branch

git rebase --onto A D #make everything after D sit on top of A

请注意,几乎可以确定在运行rebase命令时您会遇到一些冲突.修复它们后,只需运行git add .git rebase --continue.

Note that almost sure you will have some conflicts when running the rebase command. After fixing them, just run git add . and git rebase --continue.

这篇关于将一些提交移到另一个分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆