Git工作流程:将现有分支合并到新分支并删除旧分支 [英] Git workflow: Merge existing branch to new branch and delete old one

查看:215
本文介绍了Git工作流程:将现有分支合并到新分支并删除旧分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景: 在主分支上

  1. git checkout target_branch

  1. git checkout target_branch

git checkout new_branch

git checkout new_branch

git commit -m:目标分支任务号,新分支任务号:消息"

git commit -m: "TARGET BRANCH TASK NUMBER,NEW BRANCH TASK NUMBER: Message"

git push origin new_branch

git push origin new_branch

git checkout target_branch

git checkout target_branch

git push origin target_branch

git push origin target_branch

合并请求(目标- target_branch )

merge request (target - target_branch)

据我了解,我的 new_branch 不是从 target_branch 创建的,因为首先我是从 > new_branch ,然后才按下 target_branch (只是忘了它).

As I understand my new_branch isn't created from target_branch because firstly I made push from new_branch and only then I pushed target_branch (just forgot it).

所以请帮助我,下一步请正确执行:

So help me please do properly the next:

我要和我的朋友在 target_branch 中工作,我们将从中创建分支.

I'm going to work in target_branch with my friend, and we will create our branches from it.

我现在需要从 target_branch 创建我的 new_branch ,并删除旧的 new_branch (我想现在似乎是从master而不是target_branch创建的).

I need now make my new_branch to be created from target_branch and delete old new_branch (that, I suppose, now seems to be created from master not from target_branch).

如何正确执行此操作(针对Git历史记录)?

How can I do this properly (for Git history)?

推荐答案

要更改从target_branch(或master您可以使用相同的方法)检出的new_branch:

To change new_branch checked out from target_branch (or master you can use same method):

git checkout target_branch
git cherry-pick target_branch..new_branch
git branch -f new_branch
git checkout new_branch

注意:

-如果存在樱桃拾取冲突,则可以修改并保存冲突文件,然后使用git add .git cherry-pick --continue. -如果不想在target_branch的顶部重新设置n ew_branch的基数,则可以使用git checkout <an history commit of target_branch>,然后使用上述命令重新设置new_branch的基数.如下图所示,如果您使用git checkout B,并且在执行上述命令后,分支将如下所示:

-If there has cherry-pick conflicts, you can modify and save the conflict files, then use git add . and git cherry-pick --continue. -If you don’t want to rebase new_branch on the top of target_branch, you can use git checkout <an history commit of target_branch>, and then use above commands to rebase new_branch. As below graphs, if you use git checkout B, and after above commands, the branches will look like:

# Original branch structure

    A---B---C target_branch

    D---E---F new_branch

# After rebase new_branch from commit B

    A---B---C target_branch
         \
          D'---E'---F' new_branch

这篇关于Git工作流程:将现有分支合并到新分支并删除旧分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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