同步两个仅有几个文件不同的 GIT 分支
我为当前项目定义了几个分支,其中除了主分支之外的所有分支与主分支的区别仅在于相同的一小组文件(少于十个)。
在 master 中实现新功能后,我想以最少的努力将这些更改和添加复制到其他分支。这里推荐的方法是什么?
I have a couple of branches defined for the current project where all but the master branch differ from master only by the same small set of files (less than ten).
After implementing a new feature in master I would like to replicate those changes and additions to the other branches with the least effort. What's the recommended approach here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您有三个选择:
合并
:如果 master 的所有更改都需要在一个分支中可见,则很有趣,但情况并非总是如此< code>cherry-pick:仅将某些提交应用于分支
rebase
:如果您的分支尚未推送,则最好的解决方案 >:您在 master 之上重放分支的提交但是:在这三种情况下,您需要签出您想要集成更改的分支,并对每个分支重复此操作。
除非您的分支是从一个分支到另一个分支:
在这种情况下,您可以:
git checkout B1
,git merge B2
)You have three choices:
merge
: interesting if all changes of master need to be visible in one branch, but that is not always the casecherry-pick
: to only apply certain commit to a branchrebase
: the best solution if your branch has not yet been pushed: you replay the commit of your branch on top of masterBut: in the three cases, you need to checkout the branch where you want to integrate the changes, and repeat that for each branches.
Unless your branches are made from one to another:
In that case, you could:
git checkout B1
,git merge B2
)通常,当我在一个分支(甚至可能是主分支)上修复一些重要的事情时,如果我希望将相同的修复复制到另一个分支,我会执行 git checkout my_latest_feature 和 git merge - -no-commit master
从未尝试过cherry-pick,但我认为,这是我猜的最好方法,因为cherry-pick只会合并特定的更改,并且
git merge --no-commit master
将尝试获取整个树(甚至除了最新修复之外的其他提交)。我总是讨厌任何篡改提交历史的命令。这就是为什么我从来没有 rebase
更新:刚刚发现了这个类似的问题:如何将提交从一个分支复制到另一个分支?
Normally when I fix some important thing on one branch(may even be master), and if I want the same fix to be replicated to another branch, I do
git checkout my_latest_feature
andgit merge --no-commit master
Never tried cherry-pick, but I think, thats the best way I guess, as cherry-pick will only merge that specific change and
git merge --no-commit master
will try to get the whole tree(even other commits besides the latest fix).I always hate any command which tampers commit history. Thats the reason why I never rebase
Update: just found this similar question: How to copy commits from one branch to another?