简体   繁体   English

Git将分支的一部分与其他分支同步

[英]Git syncing part of a branch with other branches

We have a situation where there are 3 developers working on 3 feature branches. 我们的情况是,有3个开发人员在3个功能分支上工作。 All three developers contributed to a single CSS utility file. 所有三个开发人员都贡献了一个CSS实用程序文件。 Now we are in a situation where the features are incomplete but we need to sync just this utility file across all 3 branches because none of the features can be completed with out the merged file. 现在我们处于功能不完整的情况,但是我们只需要在所有三个分支上同步此实用程序文件,因为没有任何功能就无法完成合并文件。

What should have happened is that the utility file should have been completed on its own feature branch then merged back in, and they the 3 branches would branch from that point in time but that didnt happen unfortunately. 应该发生的是,该实用程序文件应该已经在其自己的功能分支上完成,然后合并回去,并且这3个分支将从该时间点开始分支,但是不幸的是没有发生。

Is there a way to sync a single file across branches? 有没有一种方法可以跨分支同步单个文件?

Checkout master, and make a new feature branch. 结帐母版,并创建一个新的功能分支。

Make a commit containing only the utility file 进行仅包含实用程序文件的提交

Merge that into each feature branch 将其合并到每个功能分支中

You don't sync files to keep feature branches up to date. 您不同步文件以使功能分支保持最新。 You add commits to the base of the branch. 您将提交添加到分支的基础。 The proper way to do this is with a rebase . 正确的方法是使用rebase

Make the change in one place on the branch that all three feature branches are based on. 在所有三个功能分支都基于的分支上的一个位置进行更改。 Then, you can individually rebase the feature branches. 然后,您可以分别为功能分支重新设置基础。

$ git checkout feature_one # switch to branch
$ git rebase original_branch

This will remove all the commits the dev has made to the feature branch since it was created, add your commit from the original branch, then re apply all the feature's commits again. 这将删除开发人员自功能分支创建以来所做的所有提交,从原始分支中添加您的提交,然后再次重新应用所有功能的提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM