将分叉转到现有分支的新分支

将分叉转到现有分支的新分支

本文介绍了将分叉转到现有分支的新分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑您有一个存储库 https://gitlab.com/my_repo ,其中至少有两个分支 Master Develop .您已将存储库分叉到一个私有的 https://gitlab.com/my_repo_fork 中.您已经对 Master 分支进行了一些编辑.现在,您要将本地 Master 转换为原始存储库的新分支,该分支从 Develop 分支分支.所以我有

Consider that you have a repository https://gitlab.com/my_repo with at least two branches Master and Develop. You have forked the repo into a private one https://gitlab.com/my_repo_fork. You have applied some edits to the Master branch. Now you want to turn the local Master into a new branch of the original repo, branched from the Develop branch. So What I have

  • https://gitlab.com/my_repo

  • Master
  • 开发

https://gitlab.com/my_repo_fork

  • Master *(已编辑)
  • 开发
  • Master* (edited)
  • Develop

以及我想拥有的东西

  • https://gitlab.com/my_repo
    • Master
    • 开发
    •     |->改进/数量(来自编辑后的 Master *)
    • https://gitlab.com/my_repo
      • Master
      • Develop
      •      |-> Improvment/number (from the edited Master*)

      如果您能帮助我知道最安全的方法是什么,我将不胜感激.感谢您的预先支持.

      I would appreciate it if you could help me know what is the safest way to do this. Thanks for your support in advance.

      推荐答案

      我会从 master 创建一个分支,提交更改并将该分支重新建立到development分支上,然后解决合并冲突:

      I would create a branch from master, commit the changes and rebase the branch onto the develop branch and then solve merge conflicts:

      master

      git checkout -b Improvement/number // create the new branch and add changes
      git add .
      git commit -m "<message>
      git rebase Develop                 // rebase the new branch onto Develop
      

      最初,新分支包含来自master的更改:

      Initially, the new branch contains the changes from master:

      https://gitlab.com/my_repo_fork
      
      Master (now clean)
      |-> Improvment/number
      Develop
      

      rebase从 master 删除(剪切")分支并将更改应用于 Develop :

      The rebase removes ("cuts") the branch from master and applies the changes to Develop:

      Master (now clean)
      Develop
      |-> Improvment/number
      

      有关具有更好图形效果的说明,请参见 https://git-scm.com/book/en/v2/Git-Branching-Rebasing

      For a description with better graphics see https://git-scm.com/book/en/v2/Git-Branching-Rebasing

      这篇关于将分叉转到现有分支的新分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 20:13