繁体   English   中英

如何将分支机构B衍生的分支机构A应用于分支机构C(不将B应用于C)?

[英]How to apply branch A born from branch B to branch C (without applying B to C)?

我有这些分支:

git分支-a

我们称呼他们为:

MmasterPlimpiezaPropiedadesFlistaYFormularios

P是从M创建的,当我创建F时,我签出了P。 但是,这两个分支并不相关,我最近才意识到自己做了什么。 所以现在我想将F中的提交应用于M而不应用P中的提交。

我想将两个分支“置于同一级别”:

MmasterPlimpiezaPropiedades

MmasterFlistaYFormularios

如何以最简单的方式实现这一目标?

一些潜在的解决方案:

1)。 樱桃挑

git checkout master
git cherry-pick limpiezaPropiedades..listaYFormularios   # Picks all commits in this range, not including the commit at 'limpiezaPropiedades'

2)。 变基

git checkout listaYFormularios
git rebase -i master
# Remove lines for commits that belong to limpiezaPropiedades
# BE CAREFUL, if you remove a commit that belongs to 'listaYFormularios', it will be lost and you will have to go through the reflog to recover it

您可以进行交互式变基,以删除不需要的F中的提交。 通过执行以下操作来完成此操作:

  1. 确保您已签出F
  2. 输入命令git rebase -i master
  3. 这将打开您配置的编辑器,并列出分支F上不在分支master上的所有提交。 该文件是一个脚本,在完成编辑后,rebase命令将重播该文件。 在这种情况下,由于您要做的只是从F删除一些提交,因此请删除代表您不想在F中在P中提交的行。
  4. 保存并关闭文件。 然后,Git将删除您从文件中删除的提交,并且F现在将基于master

请注意,您应该(可能)仅在未按F才这样做,因为这会导致提交哈希值发生更改,并使其他开发人员在拉您的分支时感到悲伤。

有关重新定级的更多信息,Git- 重写历史记录有一个不错的概述。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM