- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
背景
我正在尝试编写一个脚本来使用 git 简化我的向后移植过程。
在当前版本中修复错误的一般过程是这样的:
master
分支到错误修复分支,例如错误修正/abc
bugfix/abc
上的错误bugfix/abc
merge 到 master
(没有快进 merge )现在,当我想将修复程序反向移植到版本 1(分支 v1
)时,我会这样做:
bugfix/abc
创建一个新分支,例如错误修复/def
master
上手动查找 merge 提交之前的提交,例如f4d399238f
$ git rebase --onto v1 f4d399238f bugfix/def
这很好用(在发现我必须在上游 merge 之前使用提交之后)。
问题
如何在 merge 提交之前找到两个分支的共同祖先? (用于向后移植过程的第 2 步)。
尝试过
git merge-base bugfix/abc master
bugfix/abc
git log
merge #1 的结果以获取此提交的子项
--reverse
、--ancestry-path
和 --children
的各种组合,但我从未得到我期望的结果。更新
这个问题和Find common ancestor of two branches之间的关键区别是两个分支已经 merge 了。正如我提到的,最佳提交 作为 merge 分支的头返回。我需要共同的祖先在 merge 提交之前。
假设bug被修复并 merge 到master后的分支是这样的:
A---B v1
\
C---D---F---H master
\ /
E---G bugfix/abc
运行 $ git merge-base master bugfix/abc
将返回 G 但我需要得到 D (甚至 F 会为了使用 rebase --onto
的目的而做)。
一旦我得到D,我就会运行:
$ git branch bugfix/def bugfix/abc
$ git rebase --onto v1 D bugfix/def
$ git checkout v1
$ git merge bugfix/def
最终得到想要的结果:
E'---G' bugfix/def
/ \
A---B--------I v1
\
C---D---F---H master
\ /
E---G bugfix/abc
最佳答案
How do I find the common ancestor of two branches before a merge commit? (for step 2 of the backport process).
有几个选项可供使用:
git merge-base
是你要找的命令
git merge-base finds best common ancestor(s) between two commits to use in a three-way merge. One common ancestor is better than another common ancestor if the latter is an ancestor of the former. A common ancestor that does not have any better common ancestor is a best common ancestor, i.e. a merge base. Note that there can be more than one merge base for a pair of commits.
git log --decorate --graph --oneline --all
这将在日志中显示 fork 点,以便您可以跟踪分支的提交 ID。
关于git - 如何在git中 merge 提交之前找到两个分支的共同祖先?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30341998/
所以,我有一个类似于 this one 的用例,但我觉得有一些额外的细节值得提出一个新问题。 ( related questions ,供引用) 我正在编写一个实现 a cycle 的数据结构.基本设
我正在使用 Django 编写一个社交网络应用程序,需要实现类似于 Facebook“Mutual Friends”概念的功能。我有一个像这样的简单模型: class Friend(models.Mo
我有一个 iOS 应用程序,用户可以在其中使用 Facebook 登录并授予 user_friends 权限。从 Graph API 2.0 开始,Facebook 声称你无法获取两个人之间所有的共同
我想知道将来对我来说最简单的方法是什么,可以使查询既有效又不那么复杂。 我应该像这样保存双向关系吗 from_id=1, to_id=2from_id=2, to_id=1 或者只创建一个唯一的行 f
我是一名优秀的程序员,十分优秀!