在前提交中代表Git合并(假合并) [英] Represent a Git merge in former commits (fake a merge)

查看:103
本文介绍了在前提交中代表Git合并(假合并)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个分支, master 上游。偶尔,上游被导入/合并到主服务器中。



我怎样才能正确地将它们连接在一起?

使用图解释更容易:



我有:

  A  -  B  -  C  - D  -  E  -  F  -  G  -  H 
\\ | |
| /
\ /
X - Y - Z

(和我想要的):

  A  -  B  -  C  -  D  -  E  -  F  - G  -  H 
\\ | | /
| / ___ /
\ / /
X - Y - Z

我知道有一种方法可以做到这一点(使用管道命令)。

知道了!

对于那些有同样问题的人来说,这就是我所做的。请参考此处的图表,而不是原始文章(为了清晰起见,我添加了一些提交)。

首先,从日志中获取该提交的时间戳。如果稍后我们不使用这些时间戳,我们的新合并将具有比提交G..K更近的时间戳!因此,请执行 git log --format = fuller 以查看您的具有CommitDate和AuthorDate日志的每个提交。在示例场景中,我们要查找的时间戳来自提交 E 。然后:

之前:

  A  -  B  -  C -  D  -  E  -  F  -  G  -  H  -  I  -  J  -  K master 
\\ | |
| /
\ /
X - Y - Z上游

命令:

  git分支temp 
git reset --hard E
GIT_AUTHOR_DATE =...GIT_COMMIT_DATE =...git merge Z
git cherry-pick G..K

After:

  A  -  B  -  C  -  D  -  E  -  F  -  G  -  H-- I  -  J  -  K master 
\\ | | /
| / ___ /
\ / /
X - Y - Z上游


I have two branches, master and upstream. Once in a while, upstream is imported/merged into master.

How can I properly tie these back together?

It's a lot easier to explain with a diagram:

I have:

A--B--C--D--E--F--G--H
\     |
 |    /
 \   /
  X--Y--Z

It should have been (and I want):

A--B--C--D--E--F--G--H
\     |       /
 |    /   ___/
 \   /   /
  X--Y--Z

I know there's a way to do this (with the plumbing commands).

解决方案

Got it!

For those with the same problem down the road, here's what I did. Refer to the diagrams here, not in the original post (I added a few more commits for clarity).

First, grab the timestamps for that commit from the log. If we don't use these timestamps later on, our new merge will have a more recent timestamp than commits G..K! So, do git log --format=fuller to see your log with the CommitDate and AuthorDate for each commit. In the example scenario, the timestamps we're looking for are from the commit E. Then:

Before:

A--B--C--D--E--F--G--H--I--J--K         master
\     |
 |    /
 \   /
  X--Y--Z                               upstream

Commands:

git branch temp
git reset --hard E
GIT_AUTHOR_DATE="..." GIT_COMMIT_DATE="..." git merge Z
git cherry-pick G..K

After:

A--B--C--D--E--F--G--H--I--J--K         master
\     |       /
 |    /   ___/
 \   /   /
  X--Y--Z                               upstream

这篇关于在前提交中代表Git合并(假合并)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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