典型使用场景:
我有 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/