git - 向 Git 中的多个分支提交更改

标签 git one-to-many branch

典型使用场景:

我有 master、branch_foo 和 branch_bar。所有都是最新的。现在,我做了一个“git checkout master”并致力于修复错误。

假设修复是在所有分支上处于相同状态的跟踪文件上 - 即。在修复之前,来自每个分支的文件差异不会导致任何差异。

有没有办法将此修复提交到所有分支?

最佳答案

对此的常见方法是“向上 merge ”。来自 man gitworkflows:

Always commit your fixes to the oldest supported branch that require them. Then (periodically) merge the integration branches upwards into each other.

This gives a very controlled flow of fixes. If you notice that you have applied a fix to e.g. master that is also required in maint, you will need to cherry-pick it (using git-cherry-pick(1)) downwards. This will happen a few times and is nothing to worry about unless you do it very frequently.

当然首选第一种方法 - 最好只在您的存储库中提交一次,并且能够查看它如何进入每个分支的历史记录。然而,生活并不完美,有时您会发现自己属于第二类。如果这种情况变得足够普遍,您或许可以编写如下脚本

multi-cherry-pick <commit> <branch> [<branch>...]

依次检查每个分支并挑选给定的提交。

关于git - 向 Git 中的多个分支提交更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1527604/

相关文章:

git - 如何查看当前分支的 pull 请求 URL?

Git 从原点 merge 分支

sql - "one-to-many"关系上的唯一约束(无触发器)

mercurial - TortoiseHg 图表颜色的含义

svn 创建主干和分支

Git 损坏 "unable to read [sha]"但 git fsck 报告没有错误

git: 将 rep 推送到 ftp 时为 "bad line length character: Shel"

git - 如何列出 Git 1.7+ 中的所有远程分支?

hibernate - 如何将基元的 ArrayList 映射到单个列?

c# - 使用 dapper dot net orm 提取一对多关系的最佳方法?