简体   繁体   English

当合并分支已合并并已恢复时,如何强制进行合并提交?

[英]How do I force a merge commit when the branch being merge has been merged and reverted already?

In our repository, we are following a workflow based on git-flow. 在我们的存储库中,我们遵循基于git-flow的工作流程。 We had a release that was finished (installed in production), so the release branch was merged into master. 我们有一个已完成的版本(在生产中安装),因此发布分支已合并为master。

    B---C---D---E [release/1]
   /             \
  A---------------F [master]

  E - head of the release branch
  F - merge of release/1 into master

There was a problem in production, so the software was moved back to the previous version. 生产中存在问题,因此软件已移回到先前版本。 Our deployment process keeps backups, so this was done independently of source control. 我们的部署过程保留了备份,因此这是独立于源代码控制完成的。 At this point, the master branch did not match the software in production, so we reverted the commit that merged the release into master. 此时,主分支与生产中的软件不匹配,因此我们将将发布合并到主服务器的提交还原。 This brought the head of master and the software deployed in production in-sync. 这使得主人的头和生产中部署的软件同步。

    B---C---D---E
   /             \
  A---------------F---G [master]

  G - revert of release, effectively bring master back to A

The release was found to not be the problem, so we re-installed that software to production. 发现版本不是问题,因此我们将该软件重新安装到生产中。 We did this by creating a new release branch on the same commit as the old release branch. 我们通过在与旧发布分支相同的提交上创建新的发布分支来完成此操作。

    B---C---D---E [release/2]
   /             \
  A---------------F---G [master]

However, when we closed the release branch, Git did not create a merge commit, because the head of the release branch points to a set of commit that are in master's history (via the original merge). 但是,当我们关闭发布分支时,Git没有创建合并提交,因为发布分支的头部指向一组提交,这些提交位于主历史记录中(通过原始合并)。

    B---C---D---E-------+
   /             \       \
  A---------------F---G---H

  H - merge of release/2 into master (this is what we want!!)

However, due to the revert that actual changes in that release are now missing. 但是,由于恢复该版本中的实际更改现在已丢失。 How can I force Git to merge the head of the release branch a 2nd time? 我如何强制Git第二次合并发布分支的负责人?

As you noted, git doesn't do the merge because it sees those commits are in the branch's history already. 如你所知,git没有进行合并,因为它看到这些提交已经在分支的历史中。 The revert is what's in the way. 恢复是阻碍的。

I've hit this before. 我以前打过这个。 What you need to do is first revert the revert. 您需要做的是首先恢复还原。 That will remove the commit that removes the commits. 这将删除删除提交的提交。 :-) :-)

git revert G

You then probably want to re-merge just to pick up anything that happened afterwards. 然后你可能想重新合并只是为了获取之后发生的任何事情。

Generally speaking the "revert the revert" technique is the way to go. 一般来说,“恢复恢复”技术是要走的路。

You can force create a commit like you describe with something like the following. 您可以使用类似以下内容的方式强制创建提交。 You will need to tweak the various HEAD references to get the values you want. 您需要调整各种HEAD引用以获取所需的值。

git update-ref HEAD $(git log --format=%B -n 1 HEAD~1 | git commit-tree -p HEAD -p HEAD~1^2 HEAD^{tree} -F -) git update-ref HEAD $(git log --format =%B -n 1 HEAD~1 | git commit-tree -p HEAD -p HEAD~1 ^ 2 HEAD ^ {tree} -F - )

git update-ref HEAD - this should be head --format=%B -n 1 HEAD?? git update-ref HEAD - 这应该是head --format =%B -n 1 HEAD ?? - using this one to just grab a random commit message commit-tree -p HEAD - this specifies where the first parent should point (G) -p HEAD~1^2- this specifies the second parent (release/2) HEAD~1^{TREE} - this needs to point to the commit that has a tree you want to use (commit F) - 使用这个只是抓取随机提交消息commit-tree -p HEAD - 这指定第一个父应该指向的位置(G)-p HEAD~1 ^ 2-这指定第二个父(release / 2)HEAD~1 ^ {TREE} - 这需要指向具有您要使用的树的提交(提交F)

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

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